jquery - Accessing Javascript Instance from Child iFrame -
Can parent JavaScript variables and functions (originally full runtime installation) be introduced to the child's iframe?
Example:
** Guardian ** & lt; Script & gt; Function foo () & lt; / Script & gt; & Lt; Script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" & gt; & Lt; / Script & gt; ** Hair IFrame **: Function Bar () {Warning (foo); } $ (Document) .ready (function () {$ ("a"). Click (function (event) {Warning ("Thank you for visiting!");});});
Question
1) Can the bar () be called in Javascript in the hair frame?
2) Can the JPYER object be referenced in IFrame when it is declared in the original?
The answer is yes, but you will need to make additional things to do this job. In fact, using an iframe, parents have access to the window object. So an easy way to create bar available for iframe
function bar () {warning ("foo"); } Window.bar = Bar;
In the iframe, you can call again:
window.parent.bar ();
The same rules apply for objects. Please note that the main window and iframe should come from the same root (domain) and other browsers have blocked it.
Comments
Post a Comment