Jesus Ramos
Jesus Ramos

Reputation: 23266

Detecting if javascript is executing in a frame

In Firefox if I use frames[i].document.readyState it will say complete even though the frame is executing Javascript.

Is there a way to detect if Javascript is executing in a frame?

Upvotes: 1

Views: 583

Answers (2)

Andy E
Andy E

Reputation: 344793

Frames run on the same thread as their owner. You can verify this by having a child frame run a long loop whilst the parent has some code executing on a short timer — you'll notice that the parent's timer has to wait until the loop ends before it can execute its callback.

This means that a child frame and its parent cannot execute scripts simultaneously. Your check isn't running until the JavaScript in the child frame has finished executing.

Upvotes: 2

Scott Evernden
Scott Evernden

Reputation: 39986

   var in_iframe = window != window.top;

Upvotes: 1

Related Questions