[英]how to set the width and height of a new window that is opened with window.open
I have a button that opens a new window. 我有一个打开新窗口的按钮。
window.open(newUrl, '_blank', 'width=370,height=220')
I need the size of the new window to depend on the size of the screen. 我需要新窗口的大小取决于屏幕的大小。 Maybe I can set them as a percentage?
也许我可以将它们设置为百分比?
You can use two properties being screen.height and screen.width, and multiply them by any percentage you'd like. 您可以使用screen.height和screen.width这两个属性,然后将它们乘以任意百分比。
const width = document.documentElement.clientWidth * yourWidthPercentageHere;
const height = document.documentElement.clientHeight * yourHeightPercentageHere;
window.open(newUrl, '_blank', 'width=' + width + ',height=' + height);
是的,您可以将窗口大小设置为百分比,如下所示:
window.open(newUrl, '_blank', 'width="100%",height="100%"')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.