开发者

Safari mobile ignoring prevent default

开发者 https://www.devze.com 2023-02-24 11:40 出处:网络
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 vis

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 e开发者_StackOverflowxternal 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:

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

The jquery event handler still fires on click.


Instead of using

e.preventDefault();

append at the end of that function

return false;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消