stopImmediatePropagation不使用标记

问题描述 投票:0回答:2
$('a[href="/my-url"]').click(function(e) {
  e.stopImmediatePropagation()
  var win = window.open('https://newwebsite.com', '_blank');
});

我试图获得一个URL来停止在SquareSpace上打开并打开一个新的链接,但有限制我只能使用javascript。代码将打开新窗口 - 但它不会阻止旧URL在当前选项卡中打开。

javascript jquery html html5 webpage
2个回答
0
投票

使用event.preventDefault代替:

$('a[href="/my-url"]').click(e => {
  e.preventDefault();
  var win = window.open('https://newwebsite.com', '_blank');
});

0
投票
$('a[href="/my-url"]').click(function(e) {
  e.preventDefault();
  e.stopImmediatePropagation();
  var win = window.open('https://newwebsite.com', '_blank');
});
© www.soinside.com 2019 - 2024. All rights reserved.