views:

381

answers:

3

I have a web page with an IFrame named "objFrame".

In a Javascript file, the following statement is executed:

var useWindow = (typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined");

When running the code (normally or stepping through it with the debugger), the expression

(typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined")

is true when I paste it into the Watch window in Firebug, but useWindow gets the value false.

I am using Firefox 3.0.6 with Firebug 1.3.2.

What am I missing here? Please tell me that this is a simple syntactical error on my part(?!?)

A: 

It might help if you write log statements, printing the entire value, and also the "typeof" result for each component. Also enter those into the Firebug console.

Isn't "window.objFrame" only in the IE DOM?

Wouldn't it make more sense to ask questions like this in either the Firebug forum or comp.lang.javascript?

David M. Karr
A: 

I have seen something like this with Firebug as well, and have found two issues/workarounds:

  • After some weird stuff starts happening in Firebug, restarting Firefox often helps
  • I was using dojo and seeing one thing in the debugger and another thing actually happening with code pattern like this (status = true in Firebug but really undefined):

    dojo.byId("ajaxProgress").style.visibility = "hidden";

    var status = responseObject.status;

once I changed the order of those lines around, things started matching reality.

Heikki Toivonen
A: 

I'd go with

var useWindow = (window.objFrame != null
    && window.objFrame.contentWindow != null);

if at all possible.

I think that's what you're trying to detect, but checking the typeof(null) seems a bit flaky to me.

(If there's a good reason this won't work, ignore me :))

teedyay