Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10267 closed bug (fixed)

IE8 and window is(':visible') crashes

Reported by: [email protected] Owned by: timmywil
Priority: low Milestone: 1.7
Component: css Version: 1.6.4rc1
Keywords: Cc:
Blocked by: Blocking:


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 11 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

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?

comment:2 Changed 11 years ago by [email protected]

Status: pendingnew

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

var visible = !!this[ 'setTimeout' ]

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 11 years ago by [email protected]

Replying to [email protected]:

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 11 years ago by [email protected]

Replying to [email protected]:

Here was my workaround

var visible = !!this[ 'setTimeout' ]

Sorry, I can't edit my posts. :( Not used to the WikiFormatting.

var visible = !!this[ 'setTimeout' ] || $(this).is(":visible");

comment:5 Changed 11 years ago by timmywil

Component: unfiledcss
Milestone: None1.7
Owner: changed from [email protected] to timmywil
Priority: undecidedlow
Status: newassigned

This will be fixed in 1.7. #10178 was a similar situation.

comment:6 Changed 11 years 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 11 years ago by timmywil

Resolution: fixed
Status: assignedclosed

Call .is(:visible) on the window or document does not thrown an error in IE. Fixes #10267.

Changeset: 76a84fba94e0fd32b1a6612c71ef09dee39f6666

comment:8 Changed 11 years ago by anonymous

Could not reproduce.

Note: See TracTickets for help on using tickets.