Javascript jquery按钮在新选项卡和新窗口中关闭
我如何使用户单击第一个按钮时,它会在新窗口中打开?我如何使用户单击第二个按钮时,它会在同一选项卡或窗口中打开。我想通过jquery实现这一点,我不想写任何内联javascript,否则如果是这样的话,我就不会提出这个问题,我知道如何使用内联javascript实现这一点,但我想使用外部js文件和jquery实现这一点 在新窗口中打开Javascript jquery按钮在新选项卡和新窗口中关闭,javascript,jquery,hyperlink,external,Javascript,Jquery,Hyperlink,External,我如何使用户单击第一个按钮时,它会在新窗口中打开?我如何使用户单击第二个按钮时,它会在同一选项卡或窗口中打开。我想通过jquery实现这一点,我不想写任何内联javascript,否则如果是这样的话,我就不会提出这个问题,我知道如何使用内联javascript实现这一点,但我想使用外部js文件和jquery实现这一点 在新窗口中打开 <button class="button cf-button preview-bt" role="button" type="button" hre
<button class="button cf-button preview-bt" role="button" type="button" href="#">
<span class="button-content"> Preview </span>
<span class="button-icon"> </span>
</button>
<button class="button cf-button preview-bt" role="button" type="button" href="#">
<span class="button-content"> Preview </span>
<span class="button-icon"> </span>
</button>
预览
在同一窗口中打开
在新窗口中打开
<button class="button cf-button preview-bt" role="button" type="button" href="#">
<span class="button-content"> Preview </span>
<span class="button-icon"> </span>
</button>
<button class="button cf-button preview-bt" role="button" type="button" href="#">
<span class="button-content"> Preview </span>
<span class="button-icon"> </span>
</button>
预览
您不必为此使用jQuery。相反,您可以在
标记中使用以下内容:
<base target="newWindow" />
在新窗口或选项卡中打开:
$(".button").click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
对于在新弹出窗口中打开:
$(".button").click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '', 'width=100%', 'height=100%');
});
对于在同一窗口中打开:
$(".button").click(function(event) {
event.preventDefault();
event.stopPropagation();
window.location=this.href;
});
但是我也希望使用jquery,因为我在同一个页面中有许多标记,这只是我想要影响的按钮,在这种情况下,您可以使用我在答案中更新的代码!)<代码>\u blank每次打开一个新选项卡;我想你是指另一个名字。你能告诉我如何在同一个窗口中打开链接吗?现在你能再做一次js fiddle操作并告诉我如何在同一个页面中打开链接吗?因为我没有使用标签,我实际上在使用按钮。不要问我为什么选择这样做。请帮助我。除了代码不起作用的同一窗口中打开的脚本之外,其他一切都可以工作。请为我提供jquery同一窗口代码的替代代码。如果您认为这是解决方案,请将其标记为答案。如果您无法让它工作,请再次检查您的代码,可能是您的类丢失或只是删除此代码
event.stopPropagation()代码>你应该让它工作起来。