使用javascript从Web应用程序强制链接在移动Safari中打开 [英] Force link to open in mobile safari from a web app with javascript

查看:370
本文介绍了使用javascript从Web应用程序强制链接在移动Safari中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS网络应用程序中调用 window.open()时,该页面将在Web应用程序中打开,而不是移动Safari。

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

如何强制在移动版Safari中打开网页?

注意:直接使用 < a href> 链接不是一个选项。

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

推荐答案

这是可能的。使用iOS5独立网络应用程序进行测试:

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

HTML:

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

JavaScript:

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);

可以在这里测试: http://www.hakoniemi.net/labs/linkkitesti.html

这篇关于使用javascript从Web应用程序强制链接在移动Safari中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆