Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I pass messages back from the html page to native ? #168

Closed
manujbahl opened this issue Aug 21, 2018 · 3 comments
Closed

How do I pass messages back from the html page to native ? #168

manujbahl opened this issue Aug 21, 2018 · 3 comments

Comments

@manujbahl
Copy link

I tried a couple things.

  1. doing a window.open
  2. hooking into the script message mechanism by using a userContentController and WKScriptMessageHandler

nothing seems to work.

even an alert does not fire.
Here is my webview plugin

var str = "<html><body><h1>Add text below</h1><input type='text' name='email' id='email'/><button onclick='window.open(\"http:\\www.cnn.com\"); '>Click me</button></body></html>";
        var url = new Uri.dataFromString(str, mimeType: 'text/html').toString();
        
        flutterWebviewPlugin.launch(url,
                  rect: new Rect.fromLTWH(
                      00.0, 100.0, 300.0, 440.0));
 

the navigation to cnn.com does not happen on button click.
I also tried to just do an alert but did not work.

var str = "<html><body><h1>Add text below</h1><input type='text' name='email' id='email'/><button onclick='alert(\"test message\"); '>Click me</button></body></html>";

what seems to be the issue? any ideas?

@manujbahl manujbahl changed the title how doe i pass messages back from the html page to ios ? How do I pass messages back from the html page to ios ? Aug 21, 2018
@manujbahl manujbahl changed the title How do I pass messages back from the html page to ios ? How do I pass messages back from the html page to native ? Aug 21, 2018
@urmamb
Copy link

urmamb commented Mar 20, 2019

I am also having the same problem. Even alert should work.

@urmamb
Copy link

urmamb commented Mar 20, 2019

Any solution??

@charafau
Copy link
Collaborator

first of all, set enableJavascript to true when launching webiew. if you want to push messages to native from website, you need to use some javascript redirection for urls and listen to them in native.

closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants