Ticket #6088 (closed bug: fixed)
Height/Width sometimes returns document dimensions in Opera
| Reported by: | lavignep | Owned by: | |
|---|---|---|---|
| Priority: | Milestone: | 1.4.3 | |
| Component: | dimensions | Version: | 1.4.2 |
| Keywords: | height width opera | Cc: | |
| Blocking: | Blocked by: |
Description
I seems that Opera (tested only on version 10) has a scrollTo function on some elements which defeats the ("scrollTo" in elem && elem.document) test in these methods.
Anyhow, any elements in any browsers could defeat this test.
Change History
comment:2 Changed 3 years ago by gbilotta
Same issue here. For some reason, the HTMLElement prototype seems to include all the window methods, so "does it walk and quack like a window?" becomes true even though the element is _not_ the window. The change was introduced in [6313] to make it work with non-main windows and documents, but it's a little too liberal.
A possible solution is to replace that line with:
return ("scrollTo" in elem && elem.document && !elem.parentNode) ? // does it walk and quack like a window?
with the rationale that HTML elements have a parentNode while windows and documents don't.
comment:3 follow-up: ↓ 6 Changed 3 years ago by gbilotta
Posted the fix here: http://github.com/Oblomov/jquery/commit/f1fd7952743ce4a07a556f1f9a1ba175dd7bca5c
comment:6 in reply to: ↑ 3 Changed 3 years ago by sitkatech
Replying to gbilotta:
Posted the fix here: http://github.com/Oblomov/jquery/commit/f1fd7952743ce4a07a556f1f9a1ba175dd7bca5c
What's the status of this fix? Is it going to be committed to the central repository? We're having this problem and prefer not to be on a branch at this time. We've noticed this ticket was for milestone 1.4.2 but it never made it into the release. Any chance of getting this in to 1.4.3? Thanks...
comment:7 Changed 3 years ago by phildriscoll
See also http://dev.jquery.com/ticket/6575#comment:5 for a slightly different fix, and note that this problem occurs in two places in the jQuery source.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I have also a problem with returning document dimension in Opera. When I disable the prototype-library it works fine on my website.
JS Bin - Testpage:
without prototype: http://jsbin.com/eheju
with prototype: http://jsbin.com/eheju/2
JavaScript:
jQuery(function() { var i = jQuery("#test"); i.text(".width() of red box: " + i.width() + "px (css: 300px)"); });HTML (with prototype):
<!DOCTYPE html> <html> <head> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> jQuery.noConflict(); </script> <meta charset=utf-8 /> <title>Bug Test</title> <style> #test { width:300px; background:#c00; } </style> </head> <body> <div id="test"></div> </body> </html>