Hice una cuña sencilla para IE8 y otros:
window.innerWidth
window.innerHeight
window.scrollX
window.scrollY
document.width
document.height
559 bytes
(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));
Para actualizaciones, echar un vistazo a este GIST: 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));
método
Este problema se ha resuelto de varias bibliotecas tal como [jQuery] (http://jquery.com), [Prototype] (http://prototypejs.org), [YUI] (http://developer.yahoo.com/yui/), [Closure] (http://code.google.com/closure/library), o [cualquiera de varios otros] (http://en.wikipedia.org/wiki/List_of_Java Script_libraries). En lugar de resolverlo usted mismo, podría considerar aprovechar el trabajo de los demás para que pueda concentrarse en escribir un código que sea específico para sus requisitos. Alternativamente, vea cómo lo hacen y use ese código incluso si no usa la biblioteca. –
Esto fue respondido antes hace algún tiempo. Marque [this] (http://stackoverflow.com/questions/5864467/internet-explorer-innerheight) – AurA
Excepto que iOS '$ (ventana) .height()' y 'window.innerHeight' devuelven valores diferentes. Entonces, yo diría que el problema aún no se ha resuelto en esas bibliotecas y merece la pena preguntar. – cjbarth