Notalib / nativescript-webview-ext

Nativescript plugin with extended WebView functionality
Apache License 2.0
76 stars 37 forks source link

"onunload" and "onbeforeunload" methods of the webpage are getting called before "shouldOverrideUrlLoadingEvent" called. #36

Closed DeepikaKochar closed 4 years ago

DeepikaKochar commented 5 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Background of the implementation: App downloads the web content locally in the app. This web content is loaded in the Webview. There is a communication between the web content loaded and the NativeScript which we are trying to achieve through this plugin. The web content downloaded has inline weblinks (anchor tag href values) which we want to open in external browser using util.openUrl(). But at the same time "onunload" and "onbeforeunload" methods of the webpage are getting called before "shouldOverrideUrlLoadingEvent" called.

We need a solution to make sure that onbeforeunload or onunload events of the webpage are not fired when user clicks the inline links on that webpage.

Is there any code involved?

Here is the implementation of "shouldOverrideUrlLoadingEvent"

this.webViewInterface.on(WebViewExt.shouldOverrideUrlLoadingEvent, (args: ShouldOverrideUrlLoadEventData) => {
var pattern = /^((http|https|ftp):\/\/)/; var filepattern = /^((file):\/\/)/; if (filepattern.test(args.url)) { args.cancel = false; } if(pattern.test(args.url)) { args.cancel = true; util.openUrl(args.url); } });

m-abs commented 5 years ago

Hi,

I don't think this isn't something we can control. We just capture events from the WebView and I see no way to control when these events are triggered inside the WebView.