Search code examples
javascriptcordovaiframecordova-plugins

Cordova: load links in webview


I load an external website (with different HTML files) in an iframe in a cordova webview on iOS.

Now when i click a normal link in the iframe (points to another html page), the Safari browser opens with that page. But i want it to change the location inside the iframe. The only way it works is to overwrite the click action

$('a').click(function(event){
    event.preventDefault();
    window.location.replace($(this).attr('href'));
}

But that is not nice. Is there any way to prevent cordova to open links in the external safari app (perhaps in config.xml)?


Solution

  • Take a look at the cordova-plugin-whitelist plugin:

    https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/

    This plugin implements a whitelist policy for navigating the application webview on Cordova 4.0

    You may want to add to the config.xml something like:

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

    .... for each trusted domain, where example.com is the trusted domain