在JavaScript中,可以使用window.open(url, name, features)方法打开一个新窗口,并通过features参数设置新窗口的属性,包括大小、位置等。

要设置新窗口的百分比大小,可以使用widthheight属性,并将其值设置为相对于屏幕大小的百分比。

例如,要将新窗口的宽度设置为屏幕宽度的50%,高度设置为屏幕高度的80%,可以使用以下代码:

var screenWidth = window.screen.width;
var screenHeight = window.screen.height;
var width = Math.round(screenWidth * 0.5);
var height = Math.round(screenHeight * 0.8);

var features = 'width=' + width + ', height=' + height;
window.open(url, name, features);

请注意,由于浏览器的安全策略限制,一些浏览器可能会忽略widthheight属性的百分比值,或者将其自动转换为像素值。因此,无法保证所有浏览器都会正确支持百分比大小的设置。

js中windowopenurl方法里怎么设置画面的百分比大小

原文地址: https://www.cveoy.top/t/topic/jfL8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录