开发者

jQuery event.stopPropagation is not working on <a>

开发者 https://www.devze.com 2022-12-27 23:45 出处:网络
I have the following javascript: $(\'#ge-display\').click(function (event) { window.open(\'/googleearth/ge-display.php\',\'\',\'scrollbars=yes,menubar=no,height=650,width=1000,resizable=yes,toolbar=y

I have the following javascript:

$('#ge-display').click(function (event) {
  window.open('/googleearth/ge-display.php','','scrollbars=yes,menubar=no,height=650,width=1000,resizable=yes,toolbar=yes,location=no,status=no');
  event.stopPropagation();
  return false;
});

the element with id 'ge-display' i开发者_Python百科s a standard link:

<a href="/googleearth/ge-display.php" id="ge-display" target="_blank">Load Google Earth Plugin (in a new window)</a>

The problem is - when I take out the 'return false;' line from the click event handler, the javascript popup opens, and then another browser window opens - I thought stopPropagation() would prevent the links own click handler?

I've also tried stopImmediatePropagation() - but I still need to return false to stop the default behaviour of the link.


Calling event.stopPropagation() will prevent other Javascript event handlers from handling that event. It will not prevent the browser's default action.

You need to call event.preventDefault().

0

精彩评论

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