Rhyso
Rhyso

Reputation: 696

JS/Jquery syntax for IE Window width and height

I'm measuring the window and document width and height via the following properties :

//measure the window and document height and width dynamically    
var w = $(window).width();
var h = $(window).height();
var wd = $(document).width();
var hd = $(document).height();

Works fine in firefox but IE kicks up a fuss. Is there an alternative to this syntax that works in IE?
JS error recieved - could not get the position property. Invalid Argument

Upvotes: 0

Views: 1927

Answers (3)

tomasofen
tomasofen

Reputation: 1420

I had the same problem and i solve it.

The question was related with IE being in Quircks mode, because i had in the begining of the HTML some non valid tags (i copy the source from a .aspx page, and i left there the <%page ..%> directive.

When IE finds some strange tag it enters quircks mode, and some things work diferent.

When i deleted the strange tag, the $(window).width(); stuff begins to work.

Hope this helps someone in the future with my same problem. :)

Upvotes: 0

Patrick
Patrick

Reputation: 26

i just figured out, whats the "bug" in the code. Firefox is able to get width and height, whereever you put your javascript. But IE is only able to get this values when the script is within the body element. I've had the same problem here and was trying about an hour. I noticed, that the jsbin script is inside the pagebody and moved my javascript into the body and wow - it works in IE :-)

Best regards

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382696

Works for me in both FF and IE, check for yourself here.

Upvotes: 2

Related Questions