Search code examples
cordovaionic-frameworkwebviewinappbrowser

InAppBrowser Allow-Navigation ONLY MY DOMAIN when it is already open


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.


Solution

  • 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();
        }
    });