Cordova Wrapper App Where Internal Links Load In App, External Links Load In Browser

Dale Zak

I have a simple Cordova wrapper app which points to an external webpage, without defining any of its own views.

I would like all internal links from that domain to be loaded inside the app, but all external links (http://twitter.com, etc) to be loaded in the system browser, so the pages have Back / Forward functionality.

In a normal app with views, I could set target='_system' to load links in the default browser, or use the cordova-plugin-inappbrowser to explicitly open links in a web browser view. Unfortunately in this case I don't have the ability to edit the server side code, so need a solution that works within the app.

If I define the config.xml as such, then both internal and external links are loaded in app.

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />

If I define the config.xml with allow-intent, then internal and external links are opened in the system browser.

<content src="http://example.com/" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

Others have suggested using custom javascript to override the target to _system, however since I don't have my own views I can't really do that.

Is it possible to define allow-intent for the cordova-plugin-whitelist in such a way to include all URLs that are not the internal domain?

Or will I need to somehow override shouldStartLoadWithRequest in MainViewController and then call [[UIApplication sharedApplication] openURL:url]?

Dale Zak

Ok, after some experimenting and suggestions from Hayyaan, I was able to come up with combination of allow-navigation and allow-intent which served my purpose.

<content src="https://example.com/" />
<access origin="*" />
<allow-navigation href="about:*" />
<allow-navigation href="https://example.com/*" />
<allow-navigation href="https://*.example.com/*" />
<allow-navigation href="https://*.facebook.com/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

Now all internal links from the website domain are loaded in the app, while external links are loaded in the system browser.

Note, I included <allow-navigation href="https://*.facebook.com/*" /> to allow loading of Facebook libraries otherwise I received an error.

ERROR Internal navigation rejected - 
<allow-navigation> not set for url='https://staticxx.facebook.com/connect/xd_arbiter.php?

And also included <allow-navigation href="about:*" /> to avoid an error for about:blank.

ERROR Internal navigation rejected - <allow-navigation> not set for url='about:blank'

Hopefully this helps someone else with the same problem :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

External Links to load OUTSIDE of Ionic / Cordova app

From Dev

Is it possible to load an external website inside a Cordova mobile app on Windows?

From Dev

Is it possible to load an external website inside a Cordova mobile app on Windows?

From Dev

Cordova adding port to external links on cordova run browser

From Dev

How can I make Google Chrome's App Mode open external links in an external browser?

From Dev

tel and mailto Links Stopped Working in cordova app

From Dev

Cordova Load Remote Site into App

From Dev

Opening links in external device browser with Cordova/jQuery-mobile

From Dev

cordova-plugin-inappbrowser not opening links from APP to IOS Device default Browser

From Dev

Android WebView Opens links in browser instead of app

From Dev

mailto: links not opening mail app on Android in cordova app

From Dev

HTTP load failed (kCFStreamErrorDomainSSL, -9813) in Cordova app

From Dev

using systemjs to load files for cordova app

From Dev

How to load cordova plugin dynamically into android app

From Dev

Load an external image in <img> tag in a Chrome App

From Dev

Force browser to load last angularjs app code

From Dev

Why external links do not work on phonegap app after build

From Dev

Open external links in Phonegap Build App (iOS/Android)

From Dev

Open external links in Phonegap Build App (iOS/Android)

From Dev

Opening external links on my Ionic App does not work

From Dev

Android webview does not load the page but app load from browser

From Dev

iOS SDK, Text View - make links open in-app browser

From Dev

Force iOS Facebook App to open feed links in Browser not in WebView

From Dev

Open all links using system browser inside an ionic app

From Dev

How to prevent Facebook in app browser from opening my website links?

From Dev

Open links on a website with app

From Dev

Chrome Animating Links On Page Load

From Dev

shorthand for .load() ajax links with loader

From Dev

What are internal and external links on HTML pages?

Related Related

  1. 1

    External Links to load OUTSIDE of Ionic / Cordova app

  2. 2

    Is it possible to load an external website inside a Cordova mobile app on Windows?

  3. 3

    Is it possible to load an external website inside a Cordova mobile app on Windows?

  4. 4

    Cordova adding port to external links on cordova run browser

  5. 5

    How can I make Google Chrome's App Mode open external links in an external browser?

  6. 6

    tel and mailto Links Stopped Working in cordova app

  7. 7

    Cordova Load Remote Site into App

  8. 8

    Opening links in external device browser with Cordova/jQuery-mobile

  9. 9

    cordova-plugin-inappbrowser not opening links from APP to IOS Device default Browser

  10. 10

    Android WebView Opens links in browser instead of app

  11. 11

    mailto: links not opening mail app on Android in cordova app

  12. 12

    HTTP load failed (kCFStreamErrorDomainSSL, -9813) in Cordova app

  13. 13

    using systemjs to load files for cordova app

  14. 14

    How to load cordova plugin dynamically into android app

  15. 15

    Load an external image in <img> tag in a Chrome App

  16. 16

    Force browser to load last angularjs app code

  17. 17

    Why external links do not work on phonegap app after build

  18. 18

    Open external links in Phonegap Build App (iOS/Android)

  19. 19

    Open external links in Phonegap Build App (iOS/Android)

  20. 20

    Opening external links on my Ionic App does not work

  21. 21

    Android webview does not load the page but app load from browser

  22. 22

    iOS SDK, Text View - make links open in-app browser

  23. 23

    Force iOS Facebook App to open feed links in Browser not in WebView

  24. 24

    Open all links using system browser inside an ionic app

  25. 25

    How to prevent Facebook in app browser from opening my website links?

  26. 26

    Open links on a website with app

  27. 27

    Chrome Animating Links On Page Load

  28. 28

    shorthand for .load() ajax links with loader

  29. 29

    What are internal and external links on HTML pages?

HotTag

Archive