5

我做了一些搜索,但我看不出这是否可能。我想使用该window.open()方法打开指向窗口可用宽度和高度的链接。类似于下面的代码。

var h = $(window).height(); 
var w = $(window).width(); 

$('#window-opener').live('click',function (e) {
        window.open(this.href, 'Resource', 'toolbar=no ,location=0, status=no, titlebar=no, menubar=no,
                    width='+w', 
                    height='+h);
        e.preventDefault();
});

这可能吗?如果没有,任何人都可以推荐一种做类似事情的方法。

4

2 回答 2

7

您的代码是正确的,仅在宽度连接后缺少一个 ' :

width='+w', 

一定是

width='+ w +', 

我试过这个,也许我不明白你真的想要做什么:

var h = screen.height;
var w = screen.width;

$('#window-opener').live('click',function (e) {
    window.open(this.href, 'Resource', 'toolbar=no ,location=0, 
    status=no,titlebar=no,menubar=no,width='+w +',height=' +h);
    e.preventDefault();
});​

小提琴:http: //jsfiddle.net/UC8Ww/

于 2012-11-23T14:31:35.130 回答
2

因为你正在构建错误的字符串。

width='+w',height='+h);

你看到你错过了什么吗?希望你看到失踪+

于 2012-11-23T14:29:37.360 回答