简体   繁体   English

javascript-如何获取网页的内部html宽度

[英]javascript - how to get the inner html width of the webpage

I have a few client sites that have a width of about 900px-1000px centered, using javascript how can I find out what the actual width of the document is? 我有几个客户端站点的居中宽度大约为900px-1000px,如何使用javascript找出文档的实际宽度是多少? I don't need to know the width of the window, just the width that the actual html document is using. 我不需要知道窗口的宽度,只需知道实际html文档使用的宽度即可。

I also can't use any div id's to find it. 我也无法使用任何div ID来查找它。 I know I can use jquery for this, but I'd like to use plain javascript as jquery isn't running on all the sites. 我知道我可以为此使用jquery,但是我想使用普通的javascript,因为jquery并非在所有站点上都运行。

In jquery, I can find this out by using: 在jquery中,我可以使用以下方法找到答案:

$('body').outerWidth(true)

Can someone help? 有人可以帮忙吗?

var body = document.getElementsByTag("body")[0];
var width = body.style.width;

another option: 另外一个选项:

var body = document.getElementsByTag("body")[0];
var width = body.offsetWidth;

要查找文档的宽度,请使用:

    $(document).width();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM