我有一个能够独立运行的移动网络应用。为了防止在Safari中打开href并将它们保存在webapp中,我做了:
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;
}
});
}
但是,这也会使现有的点击事件不再起作用,这些事件与a-tags绑定在一起。
所以我尝试了这个,但它不起作用:
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;
}
}
});
}
感谢任何帮助!
答案 0 :(得分:0)
我知道这是一个老问题,所以也许你已经修好了,但无论如何我都会回答以防万一。进一步向下移动自动事件取消应该可以解决问题。
所以:
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
});
}