Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#4343 closed bug (invalid)

$(window).innerHeight throws error in FF3.0.7

Reported by: adam.straughan Owned by: brandon
Priority: major Milestone: 1.4
Component: dimensions Version: 1.3.2
Keywords: innerHeight Cc:
Blocked by: Blocking:

Description

The following page works in IE 6 and Chrome but not Firefox

firebug shows the following error; [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://jqueryjs.googlecode.com/files/jquery-1.3.2.js :: anonymous :: line 808" data: no] http://jqueryjs.googlecode.com/files/jquery-1.3.2.js Line 808

<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script> <script> $(document).ready(function(){

var calcSize = function(){

$('#ok').text('testing'); var h = $(window).innerHeight(); $('#ok').text('ok');

}

$('#content').click(calcSize); $('#ok').click(function(){$('#ok').text('ready');});

});

</script> </head> <body> <div id='ok'>click - jQuery ok?</div> <div id='content'> <p>click to demo bug</p> <p>ready -> testing === bad, ready -> ok === good</p> </div> </body> </html>

Change History (5)

comment:1 Changed 11 years ago by dmethvin

The error is on this line:

  var computedStyle = defaultView.getComputedStyle( elem, null );

defaultView=window and elem=window as well.

comment:2 Changed 11 years ago by brandon

Resolution: invalid
Status: newclosed

Only the height method operates on the window. $(window).height()

comment:3 Changed 11 years ago by adam.straughan

It may make sense that $(window).innerHeight() is invalid but if you don't know that (doc don't say 'do not use window') you can, as I did, spent time chasing your tail. I spent time breaking down my code to the simplest example so that I could post this issue.

Can I propose either a documentation change, ideally with a reason why this is invalid or (and this is obviously more work) a better diagnostics message.

comment:4 Changed 11 years ago by brandon

I went ahead and updated the docs to reflect that inner/outer methods only work on elements and to use width/height for document and window. As of right now there really isn't an inner/outer height of the window nor document. There is only the width/height. That is why using the inner/outer methods for window/document are invalid.

Sorry for the short explanation earlier. I understand the effort involved in debugging and posting a bug. Thanks for your effort and I hope this doesn't discourage you from doing so again in the future. :(

comment:5 Changed 11 years ago by raf

It may be worth mentioning that $(window).height() and window.innerHeight don't return the same value in Firefox. $(window).height() should be a clone of window.innerHeight for all browsers except IE, as it is the most reliable way of measuring the height of the inside of the viewport. For IE, the document.documentElement (for standards mode) and document.body (quirms mode) route should be used.

Note: See TracTickets for help on using tickets.