在弹出的窗口中打开链接的JavaScript [关闭](Open link in Popup Win

2019-09-01 00:09发布

我想A HREF加载到特定尺寸的弹出窗口也居中在屏幕上。

下面是我的源:

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

这里是我的javascript:

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");
}

这似乎测试时返回404错误。 我究竟做错了什么?

感谢堆。

Answer 1:

function windowpop(url, width, height)的函数需要一个URL返回到它。

onclick="return windowpop(545, 433)"你只是在返回widthheight

请返回使用URL this.href

onclick="return windowpop(this.href, 545, 433)"

例如: http://jsfiddle.net/zKKAM/1/



文章来源: Open link in Popup Window with Javascript [closed]