2

I have the following code for checking when a page within our website is being loaded in a window without toolbars or menubars (there are several other checks, like mobile devices and user agents, but I won't elaborate them here):

if (window.toolbar.visible !== true || window.menubar.visible !== true) {  
    // do some stuff  
}

It works fine everywhere except for Internet Explorer 8 which returns the following error: 'window.toolbar.visible' is null or not an object
(also happens with window.menubar.visible)

I cannot find anywhere an alternative for IE8. Any help on this?
Bonus question: Is there a decent Javascript reference like Mozilla's, but for Internet Explorer?

Thanks for reading and thinking about this problem.

YOMorales
  • 1,926
  • 1
  • 15
  • 25
  • 1
    *"Bonus question: Is there a decent Javascript reference like Mozilla's, but for Internet Explorer?"* There's [MSDN](http://msdn.microsoft.com). – T.J. Crowder Jul 11 '11 at 17:57
  • 2
    Using `!== true` is an odd way to check a boolean. Why do the explicit strict comparison? As opposed to simply `if (window.toolbar.visible || window.menubar.visible)`? (Probably off-topic, I doubt it will change the result, just find it odd.) – T.J. Crowder Jul 11 '11 at 17:58
  • @TJ: MSDN's format and eas of navigation is nowhere as elegant as MDC. – Mrchief Jul 11 '11 at 17:59
  • @Mrchief: True (and that's saying something, as MDC isn't exactly brilliant in this regard either). But if you're looking for the source of information on IE's particular brand of JavaScript and DOM support, there's no better source. – T.J. Crowder Jul 11 '11 at 18:02
  • 1
    Yeah, MSDN kinda sucks, but it is also the only reference I can find on IE's particular brand of JavaScript and DOM support. And my odd way of checking booleans is perhaps a habit of php where some functions can return 0 but not necessarily be false (like strpos). But anyway, it doesn't change anything. :P – YOMorales Jul 11 '11 at 18:05

1 Answers1

6

IE doesn't have window.toolbar or window.menubar nor do I see any alternatives for them on MSDN's page for the window object.

You can make your check not throw an error by testing for the object before testing for its property, e.g.:

if ((window.toolbar && window.toolbar.visible)
    || (window.menubar && window.menubar.visible)) {  
    // do some stuff  
}

Bonus question: Is there a decent Javascript reference like Mozilla's, but for Internet Explorer?

I think MSDN is the best you're going to do. If you're looking for the source of information on IE's particular brand of JavaScript and DOM objects, there's no better source. It's a pain to navigate, but...

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • This explains why both objects are null. Picking this as the answer because 1) your code allow to bypass this check in IE8 where it cannot be done, and 2) you answered the bonus question. Thanks! – YOMorales Jul 11 '11 at 18:12
  • @YOMorales: No worries, glad that helped. (I copied my bonus answer actualy *into* the answer, as well.) – T.J. Crowder Jul 11 '11 at 18:18