gpt4 book ai didi

android - HTML5 全屏移动应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:32:06 26 4
gpt4 key购买 nike

在我的 HTML5 应用程序中,我有以下元标记以允许该应用程序显示为全屏应用程序:

    <meta name="viewport" content="minimal-ui, width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />

<link href="~/images/icons/logo/touch-icon.png" rel="apple-touch-icon" />
<link href="~/images/icons/logo/touch-icon.png" rel="apple-touch-icon" sizes="76x76" />
<link href="~/images/icons/logo/touch-icon.png" rel="apple-touch-icon" sizes="120x120" />
<link href="~/images/icons/logo/touch-icon.png" rel="apple-touch-icon" sizes="152x152" />
<link href="~/images/icons/logo/touch-icon.png" rel="apple-touch-icon" sizes="180x180" />
<link href="~/images/icons/logo/touch-icon.png" rel="icon" sizes="192x192" />
<link href="~/images/icons/logo/touch-icon.png" rel="icon" sizes="128x128" />

但每当我单击应用程序中的链接时,它都会返回到浏览器,并带回浏览器栏。我该如何防止这种情况?

仅在适用于 iOS 的 Safari 上进行了测试 - 但为完整解决方案标记了 android

最佳答案

1) 通过此链接..希望这对您有所帮助。 https://gist.github.com/kylebarrow/1042026

2)试试这个 -(适用于 iOS 6.1、8.0.2)

$(document).ready(function(){
if (("standalone" in window.navigator) && window.navigator.standalone) {
// For iOS Apps
$('a').on('click', function(e){
e.preventDefault();
var new_location = $(this).attr('href');
if (new_location != undefined && new_location.substr(0, 1) != '#' && $(this).attr('data-method') == undefined){
window.location = new_location;
}
});
}
});

3) Ben Nadel 博客在处理同一问题方面非常出色。 https://www.bennadel.com/blog/2302-preventing-links-in-standalone-iphone-applications-from-opening-in-mobile-safari.htm

4)<head> 中添加这个您网站的一部分!

    <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 && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) {
e.preventDefault();
location.href = curnode.href;
}
},false);
}
})(document,window.navigator,'standalone');
</script>

关于android - HTML5 全屏移动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40599746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com