Atom23
Atom23

Reputation: 553

Whats the correct sintax for IE7/8 to check current window size

Can anyone suggest how to determine current window size for ie 7/8 or ie in general i need to calculate the current width in order to redirect to iframe so far i have tried this:

document.documentElement.offsetWidth - works only in ie9

document.body.offsetWidth - undefined

self.innerWidth - undefined

maybe anyone can suggest also a prototype approach?

Thanks guys!

   if(document.documentElement.offsetWidth > (old_w + new_w)){
     window.location = '/mylocation';
   }

Upvotes: 0

Views: 529

Answers (1)

khael
khael

Reputation: 2610

try this... As i have studied this is a cross-browser implementation for what you are looking:

window.$getView = function() {
        var ret = {
            width : 0,
            height : 0,
            element : null
        };
        if( typeof window.innerWidth != 'undefined') {
            ret.width = window.innerWidth;
            ret.height = window.innerHeight;
            ret.element = window;
        } else if( typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
            ret.width = document.documentElement.clientWidth;
            ret.height = document.documentElement.clientHeight;
            ret.element = document.documentElement;
        } else {
            ret.width = document.getElementsByTagName('body')[0].clientWidth;
            ret.height = document.getElementsByTagName('body')[0].clientHeight;
            ret.element = document.getElementsByTagName('body')[0];
        }
        return ret;
    }

Upvotes: 2

Related Questions