使用 Javascript 在弹出窗口中打开链接 [英] Open link in Popup Window with Javascript

查看:42
本文介绍了使用 Javascript 在弹出窗口中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 href 加载到特定尺寸的弹出窗口中,该窗口也位于屏幕中心.

I'm trying to load a href into a popup window of specific dimensions which also centers in the screen.

这是我的来源:

<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:

And here is my 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 错误.我做错了什么?

This seems to return a 404 error when tested. What am i doing wrong?

谢谢堆.

推荐答案

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

function windowpop(url, width, height) The function requires a URL to be returned to it.

onclick="return windowpop(545, 433)" 你只返回了 widthheight.

onclick="return windowpop(545, 433)" You're only returning the width and height.

尝试使用 this.href 返回 URL:

Try returning the URL using this.href:

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

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

这篇关于使用 Javascript 在弹出窗口中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆