+1
Answered

Is there an easy way to launch all links from a web tag in Safari?

thillsman 7 years ago updated by icahill (Administrator) 7 years ago 6
I think I've seen this in some demo or sample app, but I'm not finding it in the documentation. Can I display one web page or HTML file in a web view, but tell it to open any link in Safari? Basically, I'm building a single-serve web page that has a flexible list of links, but I want all the links to open sites in Safari and bounce users out of the app. Is this possible?
First you need to use the onnavigation on your web tag and assign that to an action. Inside your action you will want assign the variable to the navigation object property and use a variable and then tack a safari- in front of the URL within your load statement. This will ensure that you jump out to safari every time.


<assign property="var:website" value="[object:WEB.navigation]" />
<load url="safari-[var:website]" target="WEB" />

So something like this?


...
<main>
<web name="webview" alias="WEB" url="http://www.test.com/staticpage.html" style="webstyle" onnavigation="sendlinktosafari"></web>
<web name="hidden" alias="HIDDEN" url="" style="hidden"></web>
</main>
...
<actions>
<action name="sendlinkstosafari">
<sync>
<assign property="var:safarilink" value="[object:WEB.url]" />
<load url="safari-[var:safarilink]" target="HIDDEN" />
</sync>
</action>
</action>
...


When I assign a variable, how do I get the url from the link that's tapped? (In my example, I'm assuming it's just the url attribute ([object:WEB.url]).
you must use [object:WEB.navigation]. This object property will capture a clicked link.
Perfect! That worked wonders!

Also, what are the cross-platform implications here? Will the same thing bounce it out to Android's browser or Chrome or whatever comes standard on those things?
good question. I will have to look into a possible Android method.
For Android you can use:

<load url="http://rarewire.com" external="yes" target="WEB" />