[英]how to get length/size of a webpage using javascript
We get the webpage timing info using w3c navigation API. 我们使用w3c导航API获取网页计时信息。
we get the resource information using the resource timing API. 我们使用资源计时API获取资源信息。
Now, how to get the size of the webpage. 现在,如何获得网页的大小。 It appears that if I know when the page loaded, etc, I should know when the last byte was downloaded -- this should be enough to give me the length/size of the page.
看来,如果我知道何时加载页面等,我应该知道下载最后一个字节的时间 - 这应该足以给我页面的长度/大小。
How do I get this length/size ? 我如何获得这个长度/尺寸?
Found the answer at : How to get current page size in KB using just javascript? 找到答案: 如何使用javascript以KB为单位获取当前页面大小? .
。 User @Stev has answered it
用户@Stev已经回答了它
document.getElementsByTagName('HTML')[0].outerHTML.length;
Are you looking for the height of the browser window? 您在寻找浏览器窗口的高度吗?
window.innerHeight;
window.innerWidth;
干得好:
Math.ceil($('html').html().length / 1024) + "KB";
Since HTML files are pretty much just text files, you could count how many characters you have and that would be your web page size in bytes, assuming you have 1 character = 1 byte. 由于HTML文件几乎只是文本文件,因此您可以计算您拥有的字符数,这将是您的网页大小(以字节为单位),假设您有1个字符= 1个字节。 Then, divide by a multiple of 1024 to get KB, MB, GB etc.
然后,除以1024的倍数,得到KB,MB,GB等。
$("html").html().length / (n * 1024)
Edit with javascript only : 仅使用javascript进行修改 :
Shortcut to retrieve the root element of the document source 检索文档源的根元素的快捷方式
document.documentElement.outerHTML.length
or 要么
Retrieve the array of elements who's tag name is "html", assuming the first one is your root element (true for all valid HTML files), and count length : 检索标记名称为“html”的元素数组,假设第一个元素是您的根元素(对于所有有效的HTML文件都是true),并且计数长度:
document.getElementsByTagName("html")[0].outerHTML.length
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.