What is the proper way to open a link in safari or external browser?

  • 3
  • Problem
  • Updated 7 years ago
  • Solved
Hi!, I've read a number of posts about opening up a link in safari. Some are for old versions of phonegap, while others I am not sure.

So, what's the working solution for the current versions?

Thanks!

Igor
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes

Posted 7 years ago

  • 3
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
And by the way. I'd like to get the solution which will also waork for android (if it's possible), so that it would open the link in chrome on android too.
Photo of Gamex

Gamex

  • 4 Posts
  • 0 Reply Likes
IOS: Window.open('url','_system')
Photo of Hyginus Ugwumba

Hyginus Ugwumba

  • 1206 Posts
  • 42 Reply Likes
Hi Igor,

Use InAppBrowser with target equal to
'self' (webview), 'blank' (InAppBrowser), '_system' (system web browser
stay-in-webview with values true or false example: <preference
name="stay-in-webview" value="true" />

 if
set to true, all links (even with target set to blank) will open in the app's
webview


only use this preference if you want pages
from your server to take over your entire app

default is false

 

For more information

https://build.phonegap.com/docs/config-xml



Thanks

Hyginus

Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Hi, thanks for the reply.
I fixed the config.xml, set stay in web view to false. So how shall my links look now?
Thanks in advance.
Igor
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Hi again.
I'm not so good at coding, so I'd like to get as detailed as possible way to solve the problem, step-by-step. I hope somebody will be able to help me.
Thanks on advance.
Igor.
Photo of Hyginus Ugwumba

Hyginus Ugwumba

  • 1206 Posts
  • 42 Reply Likes
Hi Igor,

For more example and test code can be found here.

http://docs.phonegap.com/en/2.9.0/cor...

Thanks
Hyginus
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Still can't make it work.
This is my example link
<li data-icon="toprated"><a href="#" onclick="window.open('http://db.tt/DDFAqU6R', '_system');">sampletext</a>

And when i click it - nothing happens, i mean it seems to attempt to load it but nothing's going well so far. And the previous page stops respondong too.
How shall my link look to correctly open itself in safari?
Photo of Red2678

Red2678

  • 255 Posts
  • 0 Reply Likes
navigator.app.loadUrl(url, { openExternal:true } );

Try this:

<li data-icon="toprated">
<a href="#" onclick="navigator.app.loadUrl('http://db.tt/DDFAqU6R', { openExternal:true } );">sampletext</a>
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Hi!
Thanks for the help, building right now
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Well, i'm afraid no.
This didn't work too.
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
So what, no more solutions?
Photo of Hyginus Ugwumba

Hyginus Ugwumba

  • 1206 Posts
  • 42 Reply Likes
Hi Igor, is this still problem your end.?

Thanks
Hyginus
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Hi.
Yes, it hasn't been solved yet.
Photo of Oscar Abilleira Muñiz

Oscar Abilleira Muñiz

  • 157 Posts
  • 5 Reply Likes
Solved using appinbrowserplugin and

window.open(targetURL, '_system', 'location=yes')
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Is this solution suitable for ios? Or android only?
Photo of Hyginus Ugwumba

Hyginus Ugwumba

  • 1206 Posts
  • 42 Reply Likes
Cool Guys

Thanks
Hyginus
Photo of Austin Knobloch

Austin Knobloch

  • 6 Posts
  • 0 Reply Likes
I have come to find out that when I build my Phonegap app in 2.9.0, my links open in the system broswer (Safari for iOS). But when I build my app in 3.0.0+ it won't work. All links are then opened in the app webview. How could I go about fixing this and what is changing between builds?
Photo of ryan

ryan, Developer

  • 1538 Posts
  • 132 Reply Likes
Austin in 3.0.0+ make sure you are including the InAppBrowser plugin:

<gap:plugin name="com.phonegap.plugins.inappbrowser" />

https://build.phonegap.com/plugins/233

In 3.0.0 all core APIs were split into plugins.
Photo of Scott Saunders

Scott Saunders

  • 11 Posts
  • 0 Reply Likes
plugin unsupported: com.phonegap.plugins.inappbrowser
Photo of Scott Saunders

Scott Saunders

  • 11 Posts
  • 0 Reply Likes
whereas this doesn't have the error: gap:plugin name="org.apache.cordova.inappbrowser"
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
"Solved using appinbrowserplugin and

window.open(targetURL, '_system', 'location=yes')"

I'm not so pro in this, can anyone tell me how shall my code look like, assuming this solution works.

This is how it looks now


<ul>

<li data-icon="toprated">
<a href="#" onclick="window.open(http://db.tt/DDFAqU6R, '_system', 'location=yes')">some text</a>

</ul>



And i've got the plugin enabled in config.xml


<gap:plugin name="org.apache.cordova.inappbrowser" />
Photo of Eddy Verbruggen

Eddy Verbruggen, Champion

  • 375 Posts
  • 86 Reply Likes
Maybe it's nothing, but there are no quotes around your url:

window.open(http://db.tt/DDFAqU6R,

should be:

window.open('http://db.tt/DDFAqU6R',
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
I also tried pasting the example code

<!DOCTYPE html>
<html>
<head>
<title>window.open Example</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {
// external url
var ref = window.open(encodeURI('http://apache.org'), '_blank', 'location=yes');
// relative document
ref = window.open('next.html', '_self');
}

</script>
</head>
<body>
</body>
</html>


It gives me blank screen
Photo of ismael jimoh

ismael jimoh

  • 4116 Posts
  • 192 Reply Likes
Hi Igor,

Do you have your access permissions set in config.xml?

Replace cordova.js with phonegap.js as well.

Can I know the list of plugins you have installed with this?

Also do help provide app id for this.

Thanks.

Ismael
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
Yes, all external connections are allowed.
Will try when back home.
I have only inappbrowser installed.
Could you, please give me your skype or other IM, so that it would be easier to fix.
Thanks.
Photo of Igor  Blinowski

Igor Blinowski

  • 27 Posts
  • 0 Reply Likes
App ID
636930
Photo of Scott Saunders

Scott Saunders

  • 11 Posts
  • 0 Reply Likes
arrrgggg... having the exact same problem.. something so simple shouldn't be so hard.

Using build.phonegap.com

From my config.xml file:

preference name="phonegap-version" value="3.0.0"
gap:plugin name="org.apache.cordova.inappbrowser"
preference name="stay-in-webview" value="false"

inappbrowser is the only plugin included
---------------------------
javascript code that gets executed when a user taps a link:

function open_external_link(url) {

window.open(url,"_system","location=yes");
}

result:
url opens up in webview, not in external browser.

I've worked at this for hours and hours trying different things... at whits end.

app id: 591898

Cheers,
Scott
Photo of Hyginus Ugwumba

Hyginus Ugwumba

  • 1206 Posts
  • 42 Reply Likes
Hi Scott,

Can you try (url,"_blank......

Also don't forget to whitelist your external url config.xml

Thanks
Hyginus
Photo of Scott Saunders

Scott Saunders

  • 11 Posts
  • 0 Reply Likes
@Hyginus,

_blank does not work - the documentation, as it was pointed out above in the replies, says that _system will work in an external browser, whereas _blank, also documented, indicates a new top level window in the same browser (which is exactly what it does - yay). Whereas _system is currently working exactly like _blank.

The whitelist is not an option as the main links are supplied ad-hoc by my clients, and there are thousands.

Could someone actually look into why this is not working and stop with the guessing. Looking at the posts above that's all that has taken place and many of the "suggestions" are counter to each other, some are flat out wrong - indicating that people that should be in the know - aren't.

It's beginning to look like asking Adobe about their own product is going to be fruitless as this post started 3 months ago and apparently has not been resolved. I think Igor has been more than patient waiting for someone to help him out with this (3 months) and I'm just getting started.

Scott

This conversation is no longer open for comments or replies.