开发者

event.preventDefault() not stopping mailto links w/ gmail

I have a jQuery function with even.preventDefault() applied to a click on any element with the class 'editable'.

It's 开发者_运维知识库not preventing gmail from opening up it sweb interface to send an email, however. It works on systems where default mail behaviour is not set up (the one I was primarily testing on).. not sure about when it's run through Outlook or an actual mail application.

Is there some workaround for this?

$('.editable').not('video, img, textarea').click(function(event) { 
        event.preventDefault();
        loadEditor($(this));
    });

edit: I have also tried with event.stopPropagation(); but it is still going through.


The gmail interface event handling is probably happening in-browser, so try calling event.stopPropagation too.


try adding return false,

$('.editable').not('video, img, textarea').click(function(event) { 
        event.preventDefault();
        loadEditor($(this));
        return false;
    });

event.preventDefault() vs. return false


event.preventDefault() works for elements which have default behavior associated to them.

E.g. anchor elements redirect to url set in the href, form submit event submits the form. For such cases event.preventDefault() will stop its behavior.

The issue which you are facing is event bubling, you should use event.stopPropagation() along with (event.preventDefault() or return false).

 $('.editable').not('video, img, textarea').click(function(event) { 
        event.stopPropagation();
        loadEditor($(this));
        return false;
    });


I'm not sure if there is actually a way to prevent this, none of the event related jQuery commands mentioned in other answers were effective.

For the meantime, I'm removing the 'mailto' part of the link when editing is enabled and it does the job just fine.


For those of you who are still having problems figuring out why there is no effect whatsoever on the submit link button that also link to mailto, I think the problem is the Mailto: for Gmail extension for Chrome. The link works fine in Firefox. And the link works fine once the aforementioned extension is disabled in Chrome.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜