基本上我只想点击链接,一个新窗口应该打开。但是该窗口确实会在新选项卡中打开。 不知道为什么
<a href="http://www.google.com" target="_blank" style="font-size: 12px;" onclick="popupwindow(this.href, 'Redirect to')"><b>Link</b></a>
JS:Fiddle link
最佳答案
按照步骤:-
1. In html write return false to avoid default event default behaviour
2. From javascript return false
3. Check for popup blocker
JavaScript
function popupwindow(url) {
newwindow=window.open(url,'name','height=200,width=150');
if (newwindow == null || typeof(newwindow)=='undefined') {
alert('Please disable your pop-up blocker and click the "Open" link again.');
}
else {
newwindow.focus();
}
return false;
}
HTML
<a href="popupex.html" onclick="return popupwindow(this.href)"
>Link to popup</a>
关于javascript - JS 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18781477/