Window.open 浏览器高度不一致 [英] Window.open inconsistent height for browsers

查看:51
本文介绍了Window.open 浏览器高度不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此 JS 代码创建一个简单的弹出窗口:

I'm trying to create a simple pop-up window using this JS code:

window.open(this.href,"popupwindow", "width=400,height=545,innerHeight=500, left=200,top=5,scrollbars,toolbar=0,resizable");

结果弹出窗口显示不同浏览器的不同高度.我在不同浏览器上通过控制台检查了 window.innerHeight,结果如下:

The resultant pop-up window is showing different heights for different browsers. I checked the window.innerHeight through console on different browsers, and this is the result:

safari:window.innerHeight= 455

safari: window.innerHeight= 455

铬:window.innerHeight= 500

IE: window.innerHeight= 549

火狐:window.innerHeight= 544

这是 JSFiddle 链接.

我需要高度为 500 像素的弹出窗口.我怎样才能在所有浏览器中做到这一点.

I need the pop-up with the height of 500px. How can I do that across all browsers.

推荐答案

打开后调整窗口大小可以达到更好的尺寸精度:

Resizing the window after opening may achieve better size accuracy:

var win = window.open("about:blank" "popupwindow",  // about:blank for demo
  "width=400,height=500,left=200,top=5,scrollbars,toolbar=0,resizable");
// adjust size;
win.resizeBy( 400 - win.innerWidth, 500-win.innerHeight);

请求一个 400 x 500 像素的窗口,然后调整内容区域的大小以确保.对innerHeight 和width 设置的处理甚至识别可能因浏览器而异.

requests a window 400 x 500 pixels and then resizes the content area to make sure. Treatment or even recognition of innerHeight and width settings may differ between browsers.

不过

弹出窗口受用户偏好和弹出窗口拦截器的影响.例如,我将 IE 设置为在新选项卡中打开弹出窗口(上面的代码不会打开新窗口),Firefox 始终包含位置栏,并将任何试图绕过弹出窗口阻止程序的站点视为恶意站点.您可能希望提请设置要求的人员注意这一点.

Popup windows are subject to user preferences and popup blockers. For example I have IE set to open popups in a new tab (the code above does not open a new window), Firefox to always include the location bar, and regard any site that sets out to circumvent a popup blocker as malicious. You may wish to draw this to the attention of those setting the requirements.

这篇关于Window.open 浏览器高度不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆