在iOS Web应用程序中调用window.open()时,页面将在Web应用程序中打开,而不是在移动浏览器中打开。

如何强制在移动浏览器中打开网页?

注意:不能使用直接的<a href>链接。

最佳答案

这个有可能。使用iOS5独立网络应用程序进行了测试:

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

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

关于javascript - 强制使用javascript从网络应用在移动浏览器中打开链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7930001/

10-10 04:29