JavaScript/Jquery:如何从父窗口访问iframe中的表单
在这种情况下,我有一个父窗口(表单名称:pform),只要单击父窗口上的按钮,我就会向用户显示一个Iframe。Iframe最初是父窗口的一部分,但有一个工具可以解除Iframe的锁定。Iframe有一个单独的表单。我所说的撤销是指将整个iframe与表单(表单名称:cform)一起复制到一个新窗口中 如何从父窗口评估Iframe中的隐藏变量(id=“r111.o1”和“r111.o2”)JavaScript/Jquery:如何从父窗口访问iframe中的表单,javascript,jquery,forms,Javascript,Jquery,Forms,在这种情况下,我有一个父窗口(表单名称:pform),只要单击父窗口上的按钮,我就会向用户显示一个Iframe。Iframe最初是父窗口的一部分,但有一个工具可以解除Iframe的锁定。Iframe有一个单独的表单。我所说的撤销是指将整个iframe与表单(表单名称:cform)一起复制到一个新窗口中 如何从父窗口评估Iframe中的隐藏变量(id=“r111.o1”和“r111.o2”) <form method="post" action="xxx" name="pform" id="
<form method="post" action="xxx" name="pform" id="pform">
<div>
<div class="iframe">
<iframe>
<form name="cform" id="cform" >
<input type="hidden" value="1" name="r111.o1" id="r111.o1">
<input type="hidden" value="1" name="r111.o2" id="r111.o2">
...
</form>
我现在只需要一个代码,在对象rubIframe
和rubWindow
中迭代HTML元素。我走的路对吗?
提前感谢。您可以通过使用iframe contentwindow元素来使用iframe内容
然后可以调用该文件的任何函数,如
iframeContent.myfunction();
你看过这篇帖子了吗?@YatinMistry谢谢你的链接。我没有提到那件事。我在链接中尝试了解决方案。它在窗口停靠时工作。当窗口未锁定时,我将收到此错误。在FF firebug中:TypeError:
ifr为空;var ifrDoc=ifr.contentDocument | | ifr.contentWindow.document代码>发布更新的代码尝试->你尝试过这个吗?我无法从上述else部分访问cform中的函数。var is_rub_complete=ifrDoc.checkRub()代码>。在FF firebug中,我看到了错误:TypeError:ifrDoc.checkRub不是一个函数我试图使用document.getElementById(“cform”)
直接从else部分访问表单中的隐藏变量。这也不起作用。是的,我在我的项目中多次使用它,它工作正常不,在获取其内容窗口或相关文档后,您只能在父文件中使用iframe函数和变量。此变量iframeContent=(document.getElementById(“cform”).contentWindow | | document.getElementById(“cform”).contentDocument); 然后var是_rub_complete=iframeContent.checkRub();
XT.Assess = {};
XT.Assess.windows = new Array(); // creating array to keep track of the child window ( undocked)
XT.Assess.iframes = new Array(); // creating array to keep track of the iframe ( docked)
function validateRub(id) {
var rubWindow = XT.Assess.windows[id];
if( rubWindow ){ // undocked
console.log( 'rubWindow = '+rubWindow );
var rubcont = rubWindow.contentDocument || rubWindow.contentWindow.document;
console.log( 'rubcont = '+rubcont );
var rubIframe = XT.Assess.iframes[id]; // not working
console.log( 'rubrIframe = '+rubrIframe );
}
else { //docked
var rubIframe = XT.Assess.iframes[id];
console.log( 'rubIframe = '+rubIframe );
var ifr = document.getElementById('Iframe0');
console.log( 'ifr= '+ ifr);
var ifrDoc = ifr.contentDocument || ifr.contentWindow.document;
console.log( 'ifrDoc= '+ifrDoc );
var theForm = ifrDoc.getElementById('cform'); // Iframe
console.log( 'theForm= '+theForm );
}
return false;
}
var iframe = document.getElementById("yourFrameId");
var iframeContent = (iframe.contentWindow || iframe.contentDocument);
iframeContent.myfunction();