【问题标题】:Window.open resize to available width and heightWindow.open 调整到可用的宽度和高度
【发布时间】:2012-11-11 21:51:17
【问题描述】:

我已经做了一些搜索,但我看不出这是否可能。我想使用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();
});

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

【问题讨论】:

  • 你试过了吗?将你的 var 声明移动到函数中,你应该很高兴。

标签: javascript jquery fullscreen window.open


【解决方案1】:

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

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

你看到你错过了什么吗?希望你能看到丢失的+

【讨论】:

    【解决方案2】:

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

    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/

    【讨论】:

    • 上面的h和w变量的赋值搞混了。它应该是 var h = screen.height,而不是 var h = screen.width,对于 width 变量也是如此。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多