Matt
Matt

Reputation: 1

How do I open a link in the system browser from content in an in app browser in cordova?

I've seen plenty of examples of how to do this from content in the main html/js code of the cordova app,

for example:

window.open(url, "_system");

but it doesn't seem to work when the link is in the content already in an in app browser.

Any ideas how I could achieve this?

Thanks

Upvotes: 0

Views: 604

Answers (1)

unobf
unobf

Reputation: 7244

That is not quite enough, I think you are missing step 1 below. Here are the steps I am using to get this to work well:

  1. Make sure you have an access tag for the external site in your config.xml as follows (obviously replacing *google* with whatever matched your site).

    <access origin="*google.*" launch-external="yes" />

  2. Add a class to all the links you want to work this way. I use the external class name

  3. Add the following delegated event handler to your document (this example uses jQuery)

    jQuery(document).delegate('.external', 'click', function (e) { window.open(e.target.href, '_system'); e.preventDefault(); });

The e.preventDefault() is important to ensure the browser does not try to handle the click itself

Now it should work

Upvotes: 2

Related Questions