Solución:
Puedes probar
flutterWebviewPlugin.evalJavascript('alert("Hello World")')
Recuerda que el evalJavascript()
espera el JS
no HTML
, Entonces no puedes usar like
flutterWebviewPlugin.evalJavascript('<script language="JavaScript" type="text/javascript">alert("Hello World")</script>')
Aquí está el ejemplo completo para su referencia,
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class JSInWebView extends StatefulWidget {
@override
JSInWebViewState createState() {
return new JSInWebViewState();
}
}
class JSInWebViewState extends State<JSInWebView> {
final flutterWebviewPlugin = new FlutterWebviewPlugin();
// alternatively you can define variable as var js = "YOUR_SCRIPT"; and use it inside evalJavascript
@override
void initState(){
super.initState();
flutterWebviewPlugin.evalJavascript("alert('Hi, I just executed')");
}
@override
void dispose() {
flutterWebviewPlugin.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return WebviewScaffold(
url: 'https://google.com',
hidden: true,
appBar: AppBar(title: Text("Elite")),
);
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)