使用Javascript在弹出窗口中打开链接(event.preventDefault();)

时间:2014-04-25 15:15:15

标签: javascript html popup

此问题已在早些时候得到解答,并在此处结束: Open link in Popup Window with Javascript

但如果你向下滚动,你会看到这个评论:

只是注意,我正在使用这种方法,如果您不允许浏览器弹出窗口,则工作正常,但是,如果您这样做,它将打开弹出窗口两次。我通过添加event.preventDefault()解决了这个问题。单击链接,并从windowpop()的开头删除返回。 - madaaah Oct 18' 13 at 18:13

我有两次弹出的同样问题,并且不明白如何使用event.preventDefault();

function windowpop(url, width, height) {
    var leftPosition, topPosition;
    //Allow for borders.
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    //Open the window.
    window.open(url, "Window2", "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}


<li>
    <a class="sprite_stumbleupon" href="http://www.stumbleupon.com/submit?url=http://www.your_web_page_url" target="_blank" onclick="return windowpop(this.href, 545, 433)"></a>
</li>

0 个答案:

没有答案