tags:

views:

28

answers:

1

Long time lurker of stackoverflow and just trying something with iframes and jquery which I couldn't figure out an answer for.

I have jquery location in the main page but not inside the frame, in my iframe I have the usual $(document) jquery.

Unfortunately I get this error in firebug "$ is not defined"

Is there a way to get around this without calling jquery in each iframe?

+1  A: 

Each frame has a separate Javascript environment with a different global scope. (Although they can access other frames using the parent and frames properties.

Therefore, you need to include jQuery and other script files in the page inside each frame. (Including all plugins used by the frame)

If you really want to, you could write top.$('selector', document) inside a frame, but I wouldn't recommend it.

SLaks
How come you wouldn't recommend it, security flaw or slow?
wutanggrenade
Neither. It's confusing and causes unnecessary coupling.
SLaks