JQuery外部链接确认移动兼容性

JQuery external link confirm mobile compatibility

本文关键字:移动 兼容性 确认 链接 外部 JQuery      更新时间:2023-09-26
$('document').ready(function(){
    $('a.external').click(function(e){
        e.preventDefault();
        var speedBump = confirm("You are now leaving this website. Do you want to continue?");
            if (speedBump) {
                document.location.href = $(this).attr('href');
            };
    });
});

由于某些原因,这段代码不能在android和iOS上正常工作。知道为什么吗?它没有重定向预期的URL,而是重定向到同一网站的About Us页面,这没有意义。

更新:我用$(this).attr('href')代替http://www.google.com,脚本工作得很好,

这有什么原因吗?Attr不能在手机上运行?

e.target代替this。它是由事件对象设置的,以便跨浏览器使用。

http://api.jquery.com/category/events/event-object/

这是针对移动页面的,通过将我的移动jQuery从1.1.0版本更新到1.3版本,这个怪异的行为得到了解决。