How To Get Length/size Of A Webpage Using Javascript
Solution 1:
Found 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;
Solution 2:
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
Solution 3:
Are you looking for the height of the browser window?
window.innerHeight;
window.innerWidth;
Solution 4:
Here you go:
Math.ceil($('html').html().length / 1024) + "KB";
Post a Comment for "How To Get Length/size Of A Webpage Using Javascript"