Michael Amburgey
Michael Amburgey

Reputation: 21

In-App Browser not opening external links

Background

I have an app build via Ionic 4 (w/ Angular) calling the Cordova in-app browser plugin. After the splash screen, the in-app browser loads a URL that is a mobile-responsive website.

This website has urls such as:

The links that refer to someotherdomain.com or domain.com/somefilename.pdf typically have target="_blank" within the mobile-responsive html code.

Issue

As it stand now (testing via iOS), the in-app browser will not open any of the target="_blank" urls.

What I've tried

I've tried different settings and parameters, console.log(), and testing via ionic cordova build ios --prod, ionic serve and ionic cordova run browser.

  openWebpage(url: string) {
    const options : InAppBrowserOptions = {
        location                            : 'yes' 
        ,footer                             : 'no'
        ,hidenavigationbuttons              : 'yes'
        ,hidden                             : 'no'  
        ,hideurlbar                         : 'no'
        ,useWideViewPort                    : 'yes'
        //,clearsessioncache                : 'yes' 
        //,cleardata                        : 'yes'
        //,clearcache                       : 'yes' 
        ,zoom                               : 'no'            // Android only, shows browser zoom controls
        ,hardwareback                       : 'no'  
        ,mediaPlaybackRequiresUserAction    : 'no'  
        ,shouldPauseOnSuspend               : 'no'            // Android only
        ,closebuttoncaption                 : 'Close'         // iOS only
        ,disallowoverscroll                 : 'no'            // iOS only
        ,toolbar                            : 'yes'           // iOS only
        ,enableViewportScale                : 'yes'           // iOS only
        ,allowInlineMediaPlayback           : 'yes'           // iOS only
        ,presentationstyle                  : 'fullscreen'    // iOS only
        ,usewkwebview                       : 'no'
        ,toolbarposition                    : 'top'
        ,fullscreen                         : 'yes'           // Windows only
    };

 
    const browser = this.inAppBrowser.create(url,'_self',options);

Question

How can I:

Upvotes: 1

Views: 3824

Answers (1)

Shiv Kumar Baghel
Shiv Kumar Baghel

Reputation: 2480

InAppBrowser uses _blank to open url if its listed in whitelist. i'd suggest to use Apache Cordova Whitelist Plugin to whitelist the URLs you want to open.

  1. add Cordova plugin

    cordova plugin add cordova-plugin-whitelist

  2. in config.xml add <allow-intent> tags with URLs, like

    <allow-intent href="http://example.com/*" />

Upvotes: 1

Related Questions