2009年4月7日星期二

Get viewport size using JavaScript

The main idea of the JavaScript is stolen from here. I just rewrote the code a little to make common path faster.

function getViewportSize() {
var w = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || document.getElementsByTagName('body')[0].clientWidth;
var h = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || document.getElementsByTagName('body')[0].clientHeight;
return {width : w, height : h};
}





没有评论:

Technology changes life