最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Window.open resize to available width and height - Stack Overflow

programmeradmin0浏览0评论

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.

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.

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.

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.

Share Improve this question asked Nov 23, 2012 at 14:01 devdev 4,0093 gold badges25 silver badges36 bronze badges 1
  • Have you tried it? Move your var declarations into the function and you should be good to go. – Jay Blanchard Commented Nov 23, 2012 at 14:21
Add a comment  | 

2 Answers 2

Reset to default 10

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/

because you are builing your string wrong.

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

Do you see what you missed? Hopefully you see the missing +

发布评论

评论列表(0)

  1. 暂无评论