上次根據網上的教程給自己的網站弄了一個Web APP,但是給用戶的感覺卻十分糟糕。
問題說明:
怎么了?原來是打開WEB APP后在主頁上隨意打開連接,就會自作主張地打開Safari瀏覽器。原來好好的偽裝和心情就全被破壞掉了。這該如何是好?原來解決方法十分簡單。僅僅加入這些代碼就好了。實驗測試在本人的 iPhone (iOS 7.1)和iPod (iOS 6.1.4)上測試通過,根據原作者的敘述,最新的 iOS 7.0.4(iPhone 與 iPad)測試通過,代碼應該兼容性不錯,在這里分享:
問題解決:
復制代碼 代碼如下:
<script type=“text/javascript”>
//iOS Web APP中點擊鏈接跳轉到Safari 瀏覽器新標簽頁的問題
if ((“standalone” in window.navigator) && window.navigator.standalone) {
var noddy, remotes = false;
document.addEventListener(‘click',
function(event) {
noddy = event.target;
while (noddy.nodeName !== “A” && noddy.nodeName !== “HTML”) {
noddy = noddy.parentNode;
}
if (‘href' in noddy && noddy.href.indexOf(‘http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
event.preventDefault();
document.location.href = noddy.href;
}
},
false);
}
</script>
新聞熱點
疑難解答
圖片精選