Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force link to open in mobile safari from a web app with javascript

When calling window.open() in a iOS web app, the page opens in the web app instead of mobile safari.

How can I force the webpage to open in mobile safari?

Note: Using straight <a href> links is not an option.

like image 612
Aron Woost Avatar asked Oct 28 '11 13:10

Aron Woost


People also ask

How do I open links in Safari not app?

There is no way to force it to open the url in safari and not open the app. Every app will have list of urls that it can open. So you have to go to that app settings and tell that it should open in browser for the urls and not in the app.


2 Answers

This is possible. Tested with iOS5 stand-alone web app:

HTML:

<div id="foz" data-href="http://www.google.fi">Google</div> 

JavaScript:

document.getElementById("foz").addEventListener("click", function(evt) {     var a = document.createElement('a');     a.setAttribute("href", this.getAttribute("data-href"));     a.setAttribute("target", "_blank");      var dispatch = document.createEvent("HTMLEvents");     dispatch.initEvent("click", true, true);     a.dispatchEvent(dispatch); }, false); 

Can be tested here: http://www.hakoniemi.net/labs/linkkitesti.html

like image 77
Samuli Hakoniemi Avatar answered Oct 09 '22 10:10

Samuli Hakoniemi


Turns out it is NOT POSSIBLE to escape the iOS web app with a JavaScript window.open(). If you want a link to open in mobile safari you have to use <a href> links.

like image 35
Aron Woost Avatar answered Oct 09 '22 09:10

Aron Woost