Javascript Window.open 调整到可用的宽度和高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13530641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Window.open resize to available width and height
提问by dev
I've done a bit of searching but I can't see if this is possible or not. I would like to use the window.open()method to open links to the windows available width and height. Something similar to the below code.
我已经做了一些搜索,但我看不出这是否可能。我想使用该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();
});
Is this possible? If not can anybody recommend a way of doing something similar.
这可能吗?如果没有,任何人都可以推荐一种做类似事情的方法。
回答by phemt.latd
Your code is correct, only missing a ' after the width concatenation:
您的代码是正确的,仅在宽度连接后缺少一个 ':
width='+w',
must be
必须是
width='+ w +',
I've tried this, maybe i don't understand want you really want to do:
我试过这个,也许我不明白你真的想要做什么:
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();
});?
Fiddle: http://jsfiddle.net/UC8Ww/
回答by epascarello
because you are builing your string wrong.
因为你构建的字符串是错误的。
width='+w',height='+h);
Do you see what you missed? Hopefully you see the missing +
你看到你错过了什么吗?希望你看到失踪+

