在弹出窗口中用Javascript打开链接[已关闭]

前端之家收集整理的这篇文章主要介绍了在弹出窗口中用Javascript打开链接[已关闭]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将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错误.我究竟做错了什么?

感谢堆

解决方法

函数windowpop(url,height)该函数需要返回一个URL.

onclick =“return windowpop(545,433)”你只返回宽度和高度.

尝试使用this.href返回URL:

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

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

原文链接:https://www.f2er.com/js/154525.html

猜你在找的JavaScript相关文章