Skip to content

@dkordik /gist:843229
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
From an iframe, use the parent document's jQuery
/*
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
Something went wrong with that request. Please try again.