我正在尝试获取网页主体的高度。我希望它是当页面以100%缩放加载到高清屏幕上时的值。
这样做的目的是改变元数据中的视口,并能够强制移动浏览器一次加载整个页面,并阻止设计的响应性。
function calculateHeightOfBody() {
var body = document.body,
html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', /*'width='+width+',*/ 'height='+height);
alert('height is ' + height);
我有这个功能,它可以工作,但无论我是在电脑上还是在电话上打开页面,它都会给我两个不同的值。
在一台有高清屏幕的电脑上,我得到了944,在手机上我得到了2044.944是正确的值。
谢谢