我花了大部分时间将移动网络应用程序添加到我的网站中。 现在一切正常 - 链接留在应用程序中并且不在Safari中打开,带有youtube嵌入式视频的页面现在打开但是常见问题解答页面部分跳转链接仍然在Safari中打开...现在只有那些。
我使用了以下代码。
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript">
(function(document,navigator,standalone) {
// prevents links from apps from oppening in mobile safari
// this javascript must be the first script in your <head>
if ((standalone in navigator) && navigator[standalone]) {
var curnode, location=document.location, stop=/^(a|html)$/i;
document.addEventListener('click', function(e) {
curnode=e.target;
while (!(stop).test(curnode.nodeName)) {
curnode=curnode.parentNode;
}
// Condidions to do this only on links to your own app
// if you want all links, use if('href' in curnode) instead.
if(
'href' in curnode && // is a link
(chref=curnode.href).replace(location.href,'').indexOf('#') && // is not an anchor
( !(/^[a-z+.-]+:/i).test(chref) || // either does not have a proper scheme (relative links)
chref.indexOf(location.protocol+'//'+location.host)===0 ) // or is in the same protocol and domain
) {
e.preventDefault();
location.href = curnode.href;
}
},false);
}
})(document,window.navigator,'standalone');
</script>
我的跳转链接代码是:
<span class="faq-link"><a href="#faq-1">Where are...?</a></span>
单击Safari顶部的问题后,会立即打开。
TIA求助。