[英]Inject iframe javascript code to parent window
I need iframe js code to be part of the parent window. 我需要iframe js代码才能成为父窗口的一部分。 there is a way? 有一种方法?
In my case this worked perfectly. 就我而言,这很完美。
<script type="text/javascript">
var wnd = window;
if(wnd.parent){
wnd = wnd.parent;
}
wnd.$.globalEval('$.unblockUI();Dialog.hide();');
</script>
This ofcourse uses jquery, but all it does is calls execScript or eval on the current window. 当然,此过程使用jquery,但它所做的只是在当前窗口上调用execScript或eval。 I don't think there is a better way do this. 我认为没有更好的方法可以做到这一点。
Calling from parent to iframe: 从父级调用到iframe:
Suppose that your frame is called "myTargetFrame" and the function you're going to call is myFunction(): 假设您的框架称为“ myTargetFrame”,而您要调用的函数是myFunction():
document.getElementById('myTargetFrame').contentWindow.myFunction();
You can use also window.frames
instead of document.getElementById
您也可以使用window.frames
代替document.getElementById
Calling from iframe to parent: 从iframe调用到父项:
parent.document.formname.fieldname.value = [value you want to set]
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.