nativescript-community / ui-webview

Extended WebView which adds many options such as custom scheme handlers, JavaScript execution, URL capturing, and more.
Apache License 2.0
13 stars 7 forks source link

Prevent hyperlinks opening the installed App, open webpage in WebView #12

Closed liamcharmer closed 12 months ago

liamcharmer commented 1 year ago

Hi,

how do we prevent webviews from opening the app version of the website.

for Example if you have Amazon installed, and your webview opens a hyperlink of amazon, it will open the amazon app.

I've looked into the shouldOverrideUrlLoading handler but have had no luck...

Something like this? https://stackoverflow.com/questions/76054329/stop-wkwebview-from-opening-link-in-external-app

liamcharmer commented 12 months ago

Me being the dumbo I am.

You can use the event handler shouldOverrideUrlLoading

Then you just do the following:

 if (args.navigationType == "linkClicked") {
        args.cancel = true;
        this.$refs.webView.nativeView.loadUrl(args.url);
      }
  As the apps only open on hyperlink clicks it seems! So just cancel the request and load the URL via the browser.