The code below shows you a way to get the page size from even IE5.5. Since IE6, all the popular browsers have been supporting document.documentElement object, so only browser older than IE6 will be using the else code block.
The return object re is a JSON object and you can directly use re.width and re.height to get the values.
function getPageSize(doc) {
var re = {};
if (doc.documentElement && doc.documentElement.clientHeight) {
var root = doc.documentElement;
re.width = (root.clientWidth > root.scrollWidth)
? root.clientWidth : root.scrollWidth;
re.height = (root.clientHeight > root.scrollHeight)
? root.clientHeight : root.scrollHeight;
}
else {
var root = doc.body;
re.width = (window.innerWidth > root.scrollWidth)
? window.innerWidth : root.scrollWidth;
re.height = (window.innerHeight > root.scrollHeight)
? window.innerHeight : root.scrollHeight;
}
return re;
}
var re = {};
if (doc.documentElement && doc.documentElement.clientHeight) {
var root = doc.documentElement;
re.width = (root.clientWidth > root.scrollWidth)
? root.clientWidth : root.scrollWidth;
re.height = (root.clientHeight > root.scrollHeight)
? root.clientHeight : root.scrollHeight;
}
else {
var root = doc.body;
re.width = (window.innerWidth > root.scrollWidth)
? window.innerWidth : root.scrollWidth;
re.height = (window.innerHeight > root.scrollHeight)
? window.innerHeight : root.scrollHeight;
}
return re;
}
The return object re is a JSON object and you can directly use re.width and re.height to get the values.
No comments:
Post a Comment