Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Get innerWidth in Internet explorer 8

Tags:

javascript

In all recent browser:

 window.innerWidth // 1920 

In Internet explorer 8

 window.innerWidth // undefined 

What is the best way to get this value in IE8?

like image 355
antonjs Avatar asked Feb 23 '12 09:02

antonjs


1 Answers

The innerWidth is supported by IE9 not IE8, you can do this insteaad:

var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 

The above line will get you the width from IE as well as other standard-compliant browsers.


If you use jQuery, $(window).innerWidth() will give you desired result in all browsers too.

like image 81
Sarfraz Avatar answered Oct 09 '22 01:10

Sarfraz