我创建了一个 jquery 移动网络应用程序,并在其中一个按钮上链接到一个 .HTML 文件。当我将网络应用程序添加到主屏幕并点击该按钮时,它会在 safari 中打开 .HTML 页面,而不是停留在应用程序中。我在网上做了一些研究并发现了这个文件,但我仍然无法让它工作。有什么想法可以解决这个问题吗?
最佳答案
这是我使用的...适用于所有 anchor
。长话短说,它禁用每个 anchor 的默认行为,获取单击的 anchor 的 href
,然后使用 js 打开网络应用程序中的链接。仅适用于移动设备。
<script>
$(function() {
// prevent anchor links from opening in safari, web-app fix
if (("standalone" in window.navigator) && window.navigator.standalone) {
// For iOS Apps
$('a').on('touchend click', function (e) {
e.preventDefault(); return false;
var new_location = $(this).attr('href');
if (new_location != undefined && new_location.substr(0, 1) != '#' && $(this).attr('data-method') == undefined) {
window.location = new_location;
}
});
}
});
</script>
关于javascript - jquery 移动 Web 应用程序外部 HTML 页面在 Web 应用程序浏览器中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20432551/