Safari mobile ignoring prevent default

妖精的绣舞 提交于 2020-01-01 10:14:09

问题


I am using e.preventdefault() on a link which is in an infowindow on google maps.

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.

It is clearly loading the javascript because google maps along with lots of markers and the info windows are loading fine.

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 carrys on from here with other bits and bobs.

Has anyone else had any issues or knows a solution for this?

Thanks

Dave.


回答1:


Instead of using

e.preventDefault();

append at the end of that function

return false;

Then clicked <a> element will not redirect to anywhere.




回答2:


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:

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

The jquery event handler still fires on click.



来源:https://stackoverflow.com/questions/5664147/safari-mobile-ignoring-prevent-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!