I need to get the real screen resolution using JavaScript (client-side at least), but having issues with both IE and Firefox as they tend 开发者_运维问答to change this when you use the browser's built-in zoom.
How can this be done in a cross-browser friendly manner?
function getDimension() {
var width = 0, height = 0;
if( typeof( window.innerWidth ) == 'number' ) {
height = window.innerHeight;
width = window.innerWidth;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
height = document.documentElement.clientHeight;
width = document.documentElement.clientWidth;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
height = document.body.clientHeight;
width = document.body.clientWidth;
}
window.alert( 'Width = ' + width + 'Height = ' + height);
}
or (jquery)
height = $(window).height();
width = $(window).width();
精彩评论