Created
February 25, 2011 01:00
-
-
Save dkordik/843229 to your computer and use it in GitHub Desktop.
From an iframe, use the parent document's jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Lets hope you never have to do this, but if you're in an iframe that needs to use jQuery, | |
and you don't want to load the file a separate time in the iframe, this will let you use | |
the parent page's copy of jQuery, while also giving you the correct scope for selectors | |
to work as expected. | |
This version is SOL if you want to still be able to set a sub-scope from the iframe. | |
*/ | |
if (typeof(jQuery) == "undefined") { | |
var iframeBody = document.getElementsByTagName("body")[0]; | |
var jQuery = function (selector) { return parent.jQuery(selector, iframeBody); }; | |
var $ = jQuery; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesn't work :(