Ticket #10267 (closed bug: fixed)
IE8 and window is(':visible') crashes
| Reported by: | js@… | Owned by: | timmywil |
|---|---|---|---|
| Priority: | low | Milestone: | 1.7 |
| Component: | css | Version: | 1.6.4rc1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
It appears that in IE8 $(window).is(':visible'); crashes.
It probably shouldn't crash.
This seems to be the code where it crashes:
jQuery.expr.filters.hidden = function( elem ) {
var width = elem.offsetWidth,
height = elem.offsetHeight;
return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css( elem, "display" )) === "none");
};
Wondering if after the reliable offsets part we can do a check to see if elem.style exists, if it doesn't exist, then there is a good chance that it's the window itself, which "should" always be visible.
So, adding (elem.style && ...) would result in always returning "false" for the "hidden" check meaning the window is always "visible." (Since elem.style is undefined.)
return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style && (elem.style.display || jQuery.css( elem, "display" )) === "none"));
Change History
comment:2 follow-ups: ↓ 3 ↓ 4 Changed 21 months ago by js@…
- Status changed from pending to new
The docs also say that $(...) selects elements. So, since $(window) returns cleanly, it seems logical that $(window).is(':visible') should also return cleanly, instead of throwing a javascript error in IE8 since window.style is undefined and then window.style.display crashes IE8.
And your suggestions about the tabs doesn't seem logical, since $(...).is(':visible') doesn't take tabs into account for other elements.
And the time it might be used is if you have some things in an array, perhaps you're not sure what they're going to be, and you want to check if they're visible before doing something.
var things = [window, document, '#title', '.blocks']; $.each(things, function() {
var items = $(this).is(':visible'); $('#result').after('<p>Vis: ' + items.count + '</p>');
});
So, taking another look, since visible is the opposite of hidden, it seems like $(window).is(':hidden'); should always return false.
Anyways, I just submitted this because I had to work around the problem and someone mentioned that I shouldn't have to work around $(window).is(':visible'); crashing IE8.
Here was my workaround
| $(this).is(":visible"); |
Since "this" could be a link, or a div, or the document, or the window, we know that the window is the only element that has the setTimeout method, so that's how we check to see if it's a window first.
Just wanted to help out.
comment:3 in reply to: ↑ 2 Changed 21 months ago by js@…
Replying to js@…:
var things = [window, document, '#title', '.blocks']; $.each(things, function() {
var items = $(this).is(':visible'); $('#result').after('<p>Vis: ' + items.count + '</p>');
});
Oops. I was changing things around and that was an old copy/paste. You get the point though...
var things = [window, document, '#title', '.blocks'];
$.each(things, function() {
var visible = $(this).is(':visible');
}
comment:4 in reply to: ↑ 2 Changed 21 months ago by js@…
Replying to js@…:
Here was my workaround
var visible = !!this[ 'setTimeout' ] $(this).is(":visible");
Sorry, I can't edit my posts. :( Not used to the WikiFormatting.
var visible = !!this[ 'setTimeout' ] || $(this).is(":visible");
comment:5 Changed 21 months ago by timmywil
- Owner changed from js@… to timmywil
- Priority changed from undecided to low
- Status changed from new to assigned
- Component changed from unfiled to css
- Milestone changed from None to 1.7
This will be fixed in 1.7. #10178 was a similar situation.
comment:6 Changed 21 months ago by timmywil
However, the fix for this will not actually check if a window or tab is visible, but it will not throw an error. Technically, a window is always visible whether it has focus or not.
comment:7 Changed 21 months ago by timmywil
- Status changed from assigned to closed
- Resolution set to fixed
Call .is(:visible) on the window or document does not thrown an error in IE. Fixes #10267.
Changeset: 76a84fba94e0fd32b1a6612c71ef09dee39f6666
comment:10 Changed 15 months ago by anonymous
Recommended sites : design your own tattoo fonts - healthy chicken recipes ideas for dinner - ultrabook notebook tipis harga murah terbaik & tips cara download youtube downloader pakai keepvid - model rambut terbaru pria - google play store dari android market
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Hmmm. The docs are pretty clear that :visible selects elements. What would be the correct value to return here, or are you requesting that it just return a nonsense value without throwing an error? If the window is not visible (e.g., in a browser tab not being shown) should it return false? Should $(new Object).is(":visible") also return false since it is never visible? Why would someone be trying to do this?