admin管理员组文章数量:1389903
We get the webpage timing info using w3c navigation API.
we get the resource information using the resource timing 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 ?
We get the webpage timing info using w3c navigation API.
we get the resource information using the resource timing 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 ?
Share Improve this question asked Oct 26, 2015 at 17:32 anjanbanjanb 14k19 gold badges80 silver badges106 bronze badges 3- possibly already answered here: stackoverflow./questions/890221/… – GrafiCode Commented Oct 26, 2015 at 17:35
- Looking for a plain javascript(without additional libraries) answer. thank you. – anjanb Commented Oct 27, 2015 at 5:20
- @ GrafiCode Studio : thanks. User Stev on that question answered my question. – anjanb Commented Oct 27, 2015 at 6:16
4 Answers
Reset to default 4Found the answer at : How to get current page size in KB using just javascript?. User @Stev has answered it
document.getElementsByTagName('HTML')[0].outerHTML.length;
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. Then, divide by a multiple of 1024 to get KB, MB, GB etc.
$("html").html().length / (n * 1024)
Edit with javascript only :
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 :
document.getElementsByTagName("html")[0].outerHTML.length
Are you looking for the height of the browser window?
window.innerHeight;
window.innerWidth;
Here you go:
Math.ceil($('html').html().length / 1024) + "KB";
本文标签: metadatahow to get lengthsize of a webpage using javascriptStack Overflow
版权声明:本文标题:metadata - how to get lengthsize of a webpage using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744634681a2616752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论