gpt4 book ai didi

javascript - 独立iOS网络应用程序: Prevent opening Safari and keep current click-events

转载 作者:行者123 更新时间:2023-11-28 07:25:26 25 4
gpt4 key购买 nike

我有一个能够独立运行的移动网络应用程序。为了防止在 Safari 中打开 href 并将它们保留在 web 应用程序中,我这样做了:

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;
}
});
}

但是,这也会使绑定(bind)到 a 标签的现有点击事件无法运行。

所以我尝试了这个,但它不起作用:

if (("standalone" in window.navigator) && window.navigator.standalone) {
// For iOS Apps
$('a').on('click', function(e){
var ev = $._data(this, 'events');
if(!ev && !ev.click) {
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;
}
}
});
}

感谢任何帮助!

最佳答案

我知道这是一个老问题,所以也许你已经解决了它,但无论如何我都会回答,以防它对其他人有帮助。将自动事件取消进一步向下移动应该可以解决问题。

所以:

if (("standalone" in window.navigator) && window.navigator.standalone) {
// For iOS Apps
$('a').on('click', function(e){
var new_location = $(this).attr('href');
if (new_location != undefined && new_location.substr(0, 1) != '#' && $(this).attr('data-method') == undefined){
window.location.href = new_location;
return false; // Cancel the usual link-opening
}
// If the 'if' block above didn't run, process the click as normal
});
}

关于javascript - 独立iOS网络应用程序: Prevent opening Safari and keep current click-events,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721103/

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