Skip to content

beforeload event behaviour difference between android and ios #1071

@wmadev

Description

@wmadev

Bug Report

Problem

What is expected to happen?

We are using the inappbrowser to load our initial app page. After we add a listener to the "beforeload" event to intercept every next load. We check if this is an internal url from our app, if not we want the link to open in the system browser and not in the inappbrowser.

What does actually happen?

On Android this seems to work. Our first page opens, and a beforeload event is coming for every next load so we can intercept this properly. With navigator.app.loadUrl we manage to open the links in the android system browser.

On IOS this does not work. We are getting a beforeload event already for our first page which is different from android where we don't get this first event. Secondly the navigator.app.loadurl doesn't work on iOS. From what I read window.open(), cordova.InAppBrowser.open() should work but the first doesn't work, and 2nd only works for the first external link we click. For the 2nd nothing at all happens. (doesn't load in the inappbrowser, but also not in an external browser)

Information

Command or Code

     inAppBrowserRef = cordova.InAppBrowser.open("initial_url", '_blank',"beforeload=yes");

inAppBrowserRef.addEventListener('beforeload', function(params, callback){
             if(externalUrl(param)){
                 if(device.platform.toUpperCase() === 'ANDROID'){
                    navigator.app.loadUrl(params.url,{openExternal:true});
                 }else if(device.platform.toUpperCase() === 'IOS'){
                      window.open(params.url,'_system');
                 }
             }
        });

Environment, Platform, Device

IOS

Version information

"devDependencies": {
"cordova-android": "^12.0.1",
"cordova-ios": "^7.1.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-inappbrowser": "^6.0.0",
"cordova-plugin-splashscreen": "^6.0.1",
"cordova-plugin-statusbar": "^4.0.0"
},

Checklist

  • [ x] I searched for existing GitHub issues
  • [ x] I updated all Cordova tooling to most recent version
  • [ x] I included all the necessary information above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions