Hi,
I have an InAppBrowser I am using in my project.
When I try and close the browser, depending on the web page, it pops up with a dialog (Do you want to close this page kinda thing).
Any way to stop that happening and just force close the InAppBrowser?
Thank you!
HI @ryanhow
could you add here your code of in app browser
thanks
That’s classified :), but it goes like this…
Open In App Browser on a site with a window.beforeunload listener that pops open a confirmation when closing.
Call browser.close()
The browser then pops up the close prompt (as it should I expect) and closes after the dialog is dismissed. Just like when using a normal web browser.
So I was hoping there may be a way to not allow alerts and other browser prompts which block?
Work around answer: Do you control which URL is being opened? If so, you could route it through a proxy that removes the code that opens the alert…
I don’t sorry. But I had the idea to inject some JavaScript to remove the code. Doesn’t work 100%of the time though.
ryanhow:
I don’t sorry.
So the users start somewhere and then navigate to a page where this “Please confirm you want to leave” alert/confirm happens?
Yes, using GitHub - apache/cordova-plugin-inappbrowser: Apache Cordova Plugin inappbrowser you could probably do something like that.
I thought if you could maybe overwrite the alert
or confirm
function, but I don’t think (and somehow hope) this is not possible.
Yes, the navigation is to 3rd party sites. Thanks for the override idea, looks like it is quite possible . It does feel wrong though!
I’m not sure that it would be 100% reliable though. Every time a link is clicked to navigate to a new page it will need to be overridden again. Time will tell.
I’m actually quite surprised that we are allowed to inject JavaScript into the InAppBrowser. It’s like a free for all XSS.