Files
freeCodeCamp/common/app/utils/get-window-height.js
2016-07-28 23:39:17 -07:00

19 lines
416 B
JavaScript

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;
}
}