简体   繁体   English

如何获取浏览器宽度(不是文档/窗口)?

[英]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;

iFrame reference iFrame参考


To get browser width 获取浏览器宽度

javascript javascript

window.parent.width; // or innerwidth

parent reference 家长参考


To get screen width 获取屏幕宽度

javascript javascript

screen.width

screen reference 屏幕参考

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.

相关问题 如何根据浏览器窗口宽度和文档长度自动调整iframe的大小? - How to automatically resize an iframe based on browser window width and document length? 获取HTML文档的宽度以使用浏览器窗口调整大小 - Getting width of HTML document to resize with the browser window 如何获得可用于浏览器窗口内容的实际宽度? - How to get the actual width available for content on the browser window? 缩放时如何获取移动浏览器窗口的宽度 - How to get width of mobile browser window when its zoomed 如何使元素具有页面(文档)的 100% 宽度和高度,而不仅仅是窗口(浏览器)? - How do I make an element 100% width and height of the page (document) and not just the window (browser)? 获取浏览器窗口宽度,包括滚动条 - Get browser window width including scrollbar 有没有办法在最小化浏览器窗口大小的同时固定浏览器宽度/文档宽度? 3 - Is there a way to fix the Browser width/document width even while minimizing the browser window size? 3 如何设置电子浏览器窗口 DevTools 宽度? - How to set Electron Browser Window DevTools width? JavaScript - 获取文档(窗口)position 相对于浏览器 window(或屏幕) - JavaScript - get document (window) position relative to the browser window (or the screen) 如何获取浏览器“文档模式” - How to get browser “Document Mode”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM