JavaScript 弹出窗口中的动态高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31859280/
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
Dynamic Height in JavaScript Popup Window
提问by shewok
I'm trying to create a popup window that would have a fixed width but a dynamic height based on the user's screen size. Is this even possible? I've scoured this site and others to no avail.
我正在尝试创建一个弹出窗口,该窗口具有固定的宽度,但具有基于用户屏幕大小的动态高度。这甚至可能吗?我已经搜索了这个网站和其他网站,但无济于事。
I read the question below but I don't need it sized based on content.
我阅读了下面的问题,但我不需要根据内容调整大小。
Dynamic height for popups depending on content, is it possible?
I use the popup window for training. The window is auto-sized and positioned on one side of the screen and contains directions on how to use an application that takes up the remaining bit of the screen. The issue is, we have different sized monitors with different screen resolutions. Fortunately we only have to worry about IE11.
我使用弹出窗口进行训练。该窗口会自动调整大小并位于屏幕的一侧,并包含有关如何使用占据屏幕剩余部分的应用程序的说明。问题是,我们有不同尺寸的显示器,具有不同的屏幕分辨率。幸运的是,我们只需要担心 IE11。
Here's a giant disclaimer; I don't know anything about JavaScriptexcept that it exists and can possibly do what I need. I do, however, know HTML & CSS. So here's what I've got going on so far and I'm sure it's far from the proper way to do this:
这是一个巨大的免责声明;我对 JavaScript 一无所知,只知道它存在并且可以做我需要的事情。但是,我确实了解 HTML 和 CSS。所以这就是我到目前为止所做的事情,我相信这远非正确的方法:
<a href="link.html" onclick="javascript:void window.open('link.html','1429893142534','width=290,height=675,toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=0,left=0,top=0');return false;">Link</a>
I tried omitting the height completely but that didn't work. The height that's there is based on the smallest screen the user might be working on, but looks pretty silly with a larger screen & resolution. Maybe something besides JavaScript would work better?
我尝试完全省略高度,但这没有用。那里的高度基于用户可能正在使用的最小屏幕,但在更大的屏幕和分辨率下看起来很傻。也许除了 JavaScript 之外的东西会更好?
Thanks in advance for any responses!
提前感谢您的任何答复!
回答by brso05
You can do something like this:
你可以这样做:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a href="" onclick="openLink();">Link</a>
<script>
function openLink()
{
window.open('link.html','1429893142534','width=' + (parseInt(window.innerWidth) * 0.3) + ',height=' + (parseInt(window.innerHeight) * .3) + ',toolbar=0,menubar=0,location=0,status=0,scrollbars=1,resizable=0,left=0,top=0');
return false;
}
</script>
</body>
</html>
回答by Guest
<a href="link.html" onclick="javascript:void window.open('link.html','1429893142534','scrollbars=1');return false;">Link</a>
This should fulfil your requirement as it's working for me too. For more please refer here
这应该满足您的要求,因为它也对我有用。更多请参考这里