I have a mainframe and a iframe:
- I pass a function beforeIframe to mainFrame.
- mainFrame changse URL of beforeIframe to changedIFrame.
- When changedIFrame is loaded then execute the anonymous function.
The code below is what I want to do:
mainFrame.jsp
function randerLeftMenu(callBack) {
$("#ifrm").attr("src", "<ui:context />/changedIframe")
if(callBack) {
$("#ifrm").load(function() { callBack(); });
}
}
beforeIframe.jsp
(I have to manipulate DOM object.)
parent.randerLeftMenu(function() {$("#docType").val("aaa"); });
changedIframe.jsp
<input type="text" value="testVal" id="docType" class="input width2">
I’ve tried many things, but I can’t achieve that.
mainFrame
function randerLeftMenu(callBack) {
if(callBack) {
$("#ifrm").load(function() {
with(this.contentWindow) { callBack(); }
callBack.apply(this);
eval(callBack());
callBack.call(this);
$.proxy(callBack(),this.contentWindow);
});
}
}
In your example, the
$you are including within theranderLeftMenucall out of “beforeIframe.jsp” will always be scoped to the context from which it is called. Only thethisvariable can be dynamically bound to a different scope. You ought to be able to get around this though by passing the function as a string (or rely onFunction‘stoString()method) and evaluating the string dynamically.Updated to include working example (tested Firefox and IE):