JPC
JPC

Reputation: 71

jQuery scoping issues between parent and iframe

I use jQuery to create an iframe element which onLoad calls one of the parent's jQuery functions. This causes $ is not defined for the parent when it calls additional jQuery functions.

It seems as if the iframe has caused a descoping if the parent's jQuery.

The iframe is not a page (src="about:blank").

I think the iframe needs its own JavaScript/jQuery Environment but am having difficulty including it.

Any ideas? Thanks.

Upvotes: 2

Views: 1747

Answers (1)

Naftali
Naftali

Reputation: 146310

try this inside the iframe:

<script type="text/javascript">
    var $ = window.parent.$;
</script>

This will allow the child window (assuming it is under the same domain) to use the parent's $ variable (or whatever jQuery is set to)

Upvotes: 1

Related Questions