问题
I know there are a thousand threads talking about this topic, but it is that, really reading them and executing what they say, I can not find the key. And .. I have read and already tried many.
My problem is the following. I'm using InAppBrowser module (InAppBrowser from @ ionic-native / in-app-browser / ngx)
I am creating the following code.
constructor (private iab: InAppBrowser, private platform: Platform) {
this.iab.create ('http://www.myweb.com/app', '_blank', 'EnableViewPortScale = yes, location = no, hidenavigationbuttons = yes, enableViewportScale = yes, hideurlbar = yes, zoom = no, mediaPlaybackRequiresUserAction = yes');
}
This opens a browser inside my application until here, everything is correct. But, once I'm in, if I start navigating and I leave my domain, I would like it not to be possible. But once the browser is opened it is as if my application was not responsible for the domains where I browse.
Still having in my config.xml the rules of access origin, allow-navigation and allow-intent I only target my domain.
回答1:
If you really must implement IAB like this, you can prevent the loading of unauthorized URLs by using the loadstart
event listener as explained in this article, then use the close
method to exit it whenever the navigated URL is undesirable. You could also have your initial domain reloaded again. (Jump to Using the loadstart event to close the InAppBrowser in the linked article)
Anyway, you should try to avoid the InAppBrowser usage whenever possible.
回答2:
Thanks post @andreszs i found the solution.
The real problem, was that at least USING IONIC NATIVE InAppBrowser. Events like browser.on ('loadstart') are not loaded if the "Location" option is not active. Then, using angular@typescript code with ionic I was able to call the bases functions of cordova inappbrowser.
this.browser = this.iab.create(myurl, '_blank', 'location=yes');
this.browser.on('loadstart').subscribe(event => {
if(event.url.search(notMYurl) == -1) {
this.browser.close();
}
});
来源:https://stackoverflow.com/questions/57038620/inappbrowser-allow-navigation-only-my-domain-when-it-is-already-open