Ho fatto un semplice spessore per IE8 e altri:
window.innerWidth
window.innerHeight
window.scrollX
window.scrollY
document.width
document.height
559 byte
(function(d,b){var c=b.documentElement;var a=b.body;var e=function(g,h,f){if(typeof g[h]==="undefined"){Object.defineProperty(g,h,{get:f})}};e(d,"innerWidth",function(){return c.clientWidth});e(d,"innerHeight",function(){return c.clientHeight});e(d,"scrollX",function(){return d.pageXOffset||c.scrollLeft});e(d,"scrollY",function(){return d.pageYOffset||c.scrollTop});e(b,"width",function(){return Math.max(a.scrollWidth,c.scrollWidth,a.offsetWidth,c.offsetWidth,a.clientWidth,c.clientWidth)});e(b,"height",function(){return Math.max(a.scrollHeight,c.scrollHeight,a.offsetHeight,c.offsetHeight,a.clientHeight,c.clientHeight)});return e}(window,document));
Per aggiornamenti, date un'occhiata a questo succo: yckart/9128d824c7bdbab2832e
(function (window, document) {
var html = document.documentElement;
var body = document.body;
var define = function (object, property, getter) {
if (typeof object[property] === 'undefined') {
Object.defineProperty(object, property, { get: getter });
}
};
define(window, 'innerWidth', function() { return html.clientWidth });
define(window, 'innerHeight', function() { return html.clientHeight });
define(window, 'scrollX', function() { return window.pageXOffset || html.scrollLeft });
define(window, 'scrollY', function() { return window.pageYOffset || html.scrollTop });
define(document, 'width', function() { return Math.max(body.scrollWidth, html.scrollWidth, body.offsetWidth, html.offsetWidth, body.clientWidth, html.clientWidth) });
define(document, 'height', function() { return Math.max(body.scrollHeight, html.scrollHeight, body.offsetHeight, html.offsetHeight, body.clientHeight, html.clientHeight) });
return define;
}(window, document));
metodo
Questo problema è stato risolto in diverse librerie come [jQuery] (http://jquery.com), [Prototype] (http://prototypejs.org), [YUI] (http://developer.yahoo.com/yui/), [Closure] (http://code.google.com/closure/library) o [any of many others] (http://en.wikipedia.org)/wiki/List_of_Java Script_libraries). Piuttosto che risolverlo da solo, potresti prendere in considerazione l'idea di sfruttare il lavoro degli altri per concentrarti sulla scrittura di codice specifico per le tue esigenze. In alternativa, guarda come lo fanno e usa quel codice anche se non usi la libreria. –
Questa risposta è stata fatta qualche tempo fa. Controlla [this] (http://stackoverflow.com/questions/5864467/internet-explorer-innerheight) – AurA
Tranne che iOS '$ (window) .height()' e 'window.innerHeight' restituiscono valori diversi. Quindi direi che il problema deve ancora essere risolto in tali librerie e richieste di garanzie. – cjbarth