views:

25

answers:

2

Hi all, I'm trying to implement a bookmarklet where the user will click one <img/> and will be redirected to another page where he will annotate the image.

if the image is inserted within a HTML anchor:

<a href="http://anywhere.org"&gt;&lt;img src=""http://anywhere.org/image.png"/&gt;&lt;/a&gt;, 

can I prevent the anchor to be activated? I tried

event.stopPropagation();

and/or

event.preventDefault();

but it didn't work

thanks.

+2  A: 

First you can check if the event can be cancelated or not using:

var bool = event.cancelable;

And you can always try the classic

return false:

That will pretty much stop it.

Frankie
+1  A: 

You should use event.cancelBubble and return false (for IE).

But your method works fine in FF.

  var stop = function(evt)   {
     evt = evt || window.event;


     if(typeof(evt.stopPropagation) === "function") {
        evt.stopPropagation();
     }

     if(typeof(evt.preventDefault) === "function")   {
        evt.preventDefault();
     }

     // this is for IE6
     evt.cancelBubble = true;         
     return false;
  };
naikus