阻止iOS Web APP中點擊鏈接跳轉到Safari 瀏覽器新標簽頁


問題:ios封裝完之后,點擊里邊的按鈕會跳轉到網頁上

                                                                                       ——小卡遇到這個問題就是這樣解決的↓↓↓

解決方法:建議將代碼放到</head>標簽前,當然,另外存為一個js 文件引用也是可以的呦~

<script type="text/javascript">
//iOS Web APP中點擊鏈接跳轉到Safari 瀏覽器新標簽頁的問題 devework.com
//stanislav.it/how-to-prevent-ios-standalone-mode-web-apps-from-opening-links-in-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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM