[英]How to get browser width (not document/window)?
I'm struggling to find a solution to get the browser's width, not the document width. 我正在努力寻找一种解决方案来获取浏览器的宽度,而不是文档的宽度。
window.innerWidth
This is the famous method to get it but I want to get the value inside an iframe (which is smaller than browser's viewport) but with the measures from browser (not the iframe). 这是获得它的著名方法,但我想在iframe(小于浏览器的视口)中获取值,但要使用来自浏览器(而非iframe)的度量。 Like, testing in codepen or jsfiddle, I only get the width from result area.
就像在Codepen或jsfiddle中进行测试一样,我只从结果区域获取宽度。
browser (width: 1260px)
> body
> iframe (width: 260px)
> iframe (width: 1000px)
here, I want to get the browser value
let's say you have something like that 假设您有类似的事情
<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="https://www.w3schools.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
To get the iFrame width: 要获取iFrame宽度:
javascript javascript
document.getElementById("myFrame").width;
jQuery jQuery的
$("#myFrame").width;
To get browser width 获取浏览器宽度
javascript javascript
window.parent.width; // or innerwidth
To get screen width 获取屏幕宽度
javascript javascript
screen.width
You can mix all these techniques and get width of everything in your browser 您可以混合使用所有这些技术,并获得浏览器中所有内容的宽度
This? 这个?
console.log(window.outerWidth);
window.innerWidth
is the width of the area within the browser. window.innerWidth
是浏览器内区域的宽度。 window.outerWidth
is, unsurprisingly, the width of the browser itself. 毫不奇怪,
window.outerWidth
是浏览器本身的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.