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

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

问题描述

我试图将href加载到特定尺寸的弹出窗口中,该窗口也位于屏幕中央。



以下是我的来源:

 < li> 
< a class =sprite_stumbleuponhref =http://www.stumbleupon.com/submit?url=http://www.your_web_page_urltarget =_ blankonclick =return windowpop(545, 433)>< / A>
< / li>

以下是我的javascript:

  function windowpop(url,width,height){
var leftPosition,topPosition;
//允许边框。
leftPosition =(window.screen.width / 2) - ((width / 2)+ 10);
//允许标题和状态栏。
topPosition =(window.screen.height / 2) - ((height / 2)+ 50);
//打开窗口。
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,width,height)



onclick =return windowpop(545,433)您是只返回宽度高度



尝试返回URL使用 this.href

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

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


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

Here is my source:

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

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

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

Thanks heaps.

解决方案

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

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

Try returning the URL using this.href:

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

example: http://jsfiddle.net/zKKAM/1/

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

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