I've heard it's offset.width, document.documentElement.clientWidth, and window.innerWidth
I'm curious for projects which I cannot use jQuery on, which solution I should use?
function windowWidth() {
var docElemProp = window.document.documentElement.clientWidth,
body = window.document.body;
return window.document.compatMode === "CSS1Compat" && docElemProp || body && body.clientWidth || docElemProp;
}
Taken (and modified slightly from the jQuery source:
https://github.com/jquery/jquery/blob/master/src/dimensions.js#L42
See for yourself. It uses different things. document.documentElement.clientWidth is among them.
It can also use document.body.clientWidth
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With