Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run some Javascript in Flutter Webview

How can I run Javascript in flutter_webview_plugin? I tried with this:

onPressed: () {
   flutterWebviewPlugin.evalJavascript('<script language="JavaScript" type="text/javascript">alert("Hello World")</script>');
},

But nothing happens.

I thought with flutterWebviewPlugin.evalJavascript it's possible to run Javascript in a Webview. Did I do something wrong?

like image 846
Art Avatar asked May 15 '18 12:05

Art


1 Answers

flutterWebviewPlugin.evalJavascript('<script language="JavaScript" type="text/javascript">alert("Hello World")</script>')

expects JavaScript, not HTML

<script language="JavaScript" type="text/javascript">alert("Hello World")</script>

is HTML.

Try

flutterWebviewPlugin.evalJavascript('alert("Hello World")')
like image 74
Günter Zöchbauer Avatar answered Sep 18 '22 16:09

Günter Zöchbauer