0

我有许多社交媒体网站链接,我想通过弹出框解析它们。以下是其中一个链接的示例:

<li>
    <a class="sprite_reddit" href="http://www.reddit.com/submit" onclick="window.open('http://www.reddit.com/submit?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'reddit','toolbar=no,width=840,height=750'); return false;"></a>
</li>

而不是在 html 中包含 window.open 我希望此链接通过以下 javascript 进行解析,该 javascript 在屏幕中居中弹出框。

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

为了实现这一点,我需要改变什么,或者这种链接不可能?

多谢了。

4

1 回答 1

0

每个主要浏览器版本都支持打开功能,但并非每个浏览器都支持您设置的所有参数。我猜不再支持像 screenX 和 Y 这样的东西。查看此链接以获取更多信息:

http://www.w3schools.com/jsref/met_win_open.asp

于 2013-04-24T08:11:59.693 回答