简体   繁体   English

Safari 移动忽略防止默认

[英]Safari mobile ignoring prevent default

I am using e.preventdefault() on a link which is in an infowindow on google maps.我在谷歌地图信息窗口中的链接上使用e.preventdefault()

It works as expected on the desktop where the link doesn't visit the href but on Safari it seems to ignore it and visits the link as if no JavaScript is loaded.它在链接不访问href的桌面上按预期工作,但在 Safari 上它似乎忽略它并访问链接,就好像没有加载 JavaScript 一样。

It is clearly loading the javascript because google maps along with lots of markers and the info windows are loading fine.它显然正在加载 javascript,因为谷歌地图以及大量标记和信息窗口加载良好。

The code for the link is this:链接的代码是这样的:

$('.infowindow .more, .infowindow h3 a').live('click', function(e) {
    e.preventDefault();
                        
    /* Loading content from external html file */
    $('#content .content').html('<p class="loading"><img src="images/icons/loader.gif" alt="Loading content..."></p>');
    $('#content .content').load($(this).attr('href') + ' #content > *', function() {

Obviously, the code carries on from here with other bits and bobs.显然,代码从这里开始,还有其他的点点滴滴。

Has anyone else had any issues or knows a solution for this?有没有其他人有任何问题或知道解决方案?

A little late to the party here, but I'm having the same problem in 2019. I was able to fix this by putting preventDefault in the html element itself:在这里参加聚会有点晚了,但我在 2019 年遇到了同样的问题。我能够通过将 preventDefault 放在 html 元素本身中来解决这个问题:

<a href="http://dontvisitthis.com" onclick="event.preventDefault()">click</a>

The jquery event handler still fires on click. jquery 事件处理程序仍会在单击时触发。

Instead of using而不是使用

e.preventDefault();

append at the end of that function附加在该函数的末尾

return false;

Then clicked <a> element will not redirect to anywhere.然后点击<a>元素不会重定向到任何地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM