#10267 closed bug (fixed)
IE8 and window is(':visible') crashes
| Reported by: | Owned by: | timmywil | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.7 |
| Component: | css | Version: | 1.6.4rc1 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
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 (9)
comment:1 Changed 8 years ago by
| Owner: | set to js@… |
|---|---|
| Status: | new → pending |
comment:2 follow-ups: 3 4 Changed 8 years ago by
| Status: | pending → 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 Changed 8 years ago by
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 Changed 8 years ago by
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 8 years ago by
| Component: | unfiled → css |
|---|---|
| Milestone: | None → 1.7 |
| Owner: | changed from js@… to timmywil |
| Priority: | undecided → low |
| Status: | new → assigned |
This will be fixed in 1.7. #10178 was a similar situation.
comment:6 Changed 8 years ago by
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 8 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Call .is(:visible) on the window or document does not thrown an error in IE. Fixes #10267.
Changeset: 76a84fba94e0fd32b1a6612c71ef09dee39f6666
comment:10 Changed 7 years ago by
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

Hmmm. The docs are pretty clear that
:visibleselects 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 returnfalse? Should$(new Object).is(":visible")also returnfalsesince it is never visible? Why would someone be trying to do this?