javascript 如何打开一个弹出窗口,使其高度从屏幕顶部到底部?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9035699/
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
How to open a Popup window, so that it's height is from the top of the screen to the bottom?
提问by Kenci
I am trying to open a popup window, so that it height is from the top of the screen to the "applications" bar of Windows. This is the code:
我正在尝试打开一个弹出窗口,使其高度从屏幕顶部到 Windows 的“应用程序”栏。这是代码:
function windowOpener(windowHeight, windowWidth, windowName, windowUri) {
var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(windowUri, windowName, 'resizable=0,scrollbars=1,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth);
newWindow.focus();
return newWindow.name;
}
Why doesnt it work in IE? (works in chrome)
为什么它在 IE 中不起作用?(在铬中工作)
Thanks
谢谢
回答by skybondsor
I think you only need screen.width and screen.height. Don't prepend them with window.
我认为你只需要 screen.width 和 screen.height。不要在它们前面加上窗口。
Edit:Apparently IE requires a "fullscreen=yes" param.
编辑:显然 IE 需要一个“全屏=是”参数。
Try this:
试试这个:
<script type="text/javascript">
<!--
function popup(url)
{
params = 'width='+screen.width;
params += ', height='+screen.height;
params += ', top=0, left=0'
params += ', fullscreen=yes';
newwin=window.open(url,'windowname4', params);
if (window.focus) {newwin.focus()}
return false;
}
// -->
</script>
<a href="javascript: void(0)"
onclick="popup('popup.html')">Fullscreen popup window</a>
回答by studio-klik
This works for me:
这对我有用:
<a class="popme" href="http://codesheet.org">popup</a>
jQuery
jQuery
$(document).ready(function() {
$(".popme").click(function(event){
var h = 650;
var w = 340;
var wh = screen.height;
var ww = screen.width;
var top = wh/2 - h/2;
var left = ww/2 - w/2;
var popup = window.open(this.href + '', 'player', 'height=' + wh + ', width=' + w + ', scrollbars=no, left=' + left + ', top=' + top);
popup.focus();
return false;
});
});
回答by nandin
if you just want to open new window in full screen, did you try remove the height and width parameters?
如果您只想全屏打开新窗口,您是否尝试删除高度和宽度参数?
newWindow = window.open(windowUri, windowName);