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

javascript - window.open width ignored in Chrome - Stack Overflow

programmeradmin3浏览0评论

I want to create a popup of a fixed size, however the width attribute is ignored in Chrome. But Works fine in FF.

Here's my code:

window.open('','','width=300');

The resultant popup is larger than the given width.

Any suggestions?

I want to create a popup of a fixed size, however the width attribute is ignored in Chrome. But Works fine in FF.

Here's my code:

window.open('','','width=300');

The resultant popup is larger than the given width.

Any suggestions?

Share Improve this question asked Mar 18, 2013 at 7:26 Hadiyah MujhidHadiyah Mujhid 1871 gold badge2 silver badges11 bronze badges 4
  • 1 have you tried to provide height? – Jeff Robert Dagala Commented Mar 18, 2013 at 7:28
  • yes, I've tried providing height. No change in result. – Hadiyah Mujhid Commented Mar 18, 2013 at 7:29
  • 1 Strangely its works when u have a height attribute. See jsfiddle.net/YrRZu – Subir Kumar Sao Commented Mar 18, 2013 at 7:33
  • 1 my apologies. Adding height does work! I was in full-screen mode last time I tried. – Hadiyah Mujhid Commented Mar 18, 2013 at 7:44
Add a comment  | 

2 Answers 2

Reset to default 11

it would seem to be some bizarre quirk in Chrome, that you have to specify both a width and a height to get it to observe the dimensions set. If you only specify a height, or a width, then that single dimension is ignored. Hence why in the other answer it worked fine for Jeff.

I have tried to put this one on Chrome version 25.0.1364.172

window.open('','','width=200,height=100');

and it correspond the exact height and width of the window.

to check, please use

window.innerHeight; //to display height
window.innerWidth; //to display width
发布评论

评论列表(0)

  1. 暂无评论