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

Add event handler for link #360

Closed
ndusart opened this issue Mar 27, 2019 · 6 comments
Closed

Add event handler for link #360

ndusart opened this issue Mar 27, 2019 · 6 comments

Comments

@ndusart
Copy link

ndusart commented Mar 27, 2019

In a project, we want to use the webview as a rich formatted text label. This label could contains links to some urls but tapping on it must not change the url of the webview as it is not meant to show other thing than the initial text.

It would be great if we could catch the event of tapping a url link in the webview so that we can extract the intent and open the browser application or do any other appropriate action.

For Android, this could be done using shouldOverrideUrlLoading in the WebViewClient.

On iOS, this could be done using webView:decidePolicyForNavigationAction:decisionHandler: of the WKNavigationDelegate of the webview.

@5hanth
Copy link

5hanth commented Apr 10, 2019

for now i'm using url_launcher plugin to open url and goBack(). But this method still shows the ugly ERR_UNKNOWN_URL_SCHEME screen as this listener is invoked only after page is fully loaded.

flutterWebviewPlugin.onUrlChanged.listen((String url) {
  if(url.contains("whatsapp://")) {
    flutterWebviewPlugin.goBack();
    _launchURL(url);
  }
});

@MilloshFey
Copy link

for now i'm using url_launcher plugin to open url and goBack(). But this method still shows the ugly ERR_UNKNOWN_URL_SCHEME screen as this listener is invoked only after page is fully loaded.

flutterWebviewPlugin.onUrlChanged.listen((String url) {
  if(url.contains("whatsapp://")) {
    flutterWebviewPlugin.goBack();
    _launchURL(url);
  }
});

You don't need to go back. You can just launch the url and abort the load, so you stay in the same page. I think this can help you:
#292

@5hanth
Copy link

5hanth commented Apr 11, 2019

You don't need to go back.

I have a href to https://wa.me/${this.user.phone} in a page which loads whatsapp intermediate page which again loads whatsapp:// intent. intent throws a ERR_UNKNOWN_URL_SCHEME page way before onUrlChanged listener callback is invoked. it appears that callback is called only after webview loads the page (or not sure if it might be happening async). so I had to goBack() to cover it up which looks ugly though. only if we had a beforeUrlChange callback life would be more better.

P.S: or I can directly match wa.me and do the same. that's right. goBack() is not needed here.

@charafau
Copy link
Collaborator

Support to abort loading specific URLs was added in 0.3.2

@5hanth
Copy link

5hanth commented Apr 13, 2019

related issue #337

@ndusart
Copy link
Author

ndusart commented May 9, 2019

Closing this as the new webview_flutter plugin seems better in every way.

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

4 participants