Files
freeCodeCamp/common/app/utils/get-window-height.js

19 lines
416 B
JavaScript
Raw Normal View History

2016-03-05 21:06:04 -08:00
export default function getWindowHeight() {
try {
const win = typeof window !== 'undefined' ?
window :
null;
if (!win) {
return 0;
}
const docElement = win.document.documentElement;
const body = win.document.getElementsByTagName('body')[0];
return win.innerHeight ||
docElement.clientHeight ||
body.clientHeight ||
0;
} catch (e) {
return 0;
}
}