[英]JavaScript / Jquery : how to access a form present inside a iframe from parent window
I have this situation where I have a Parent window ( form name : pform), on click of a button on Parent Window, I display an Iframe to the User. 在这种情况下,我有一个父窗口(表单名称:pform),单击父窗口上的一个按钮,就会向用户显示一个iframe。 The Iframe is part of the Parent window initially, but there is a facility that Iframe can be Undocked. Iframe最初是“父”窗口的一部分,但存在可以将Iframe取消对接的功能。 The Iframe has a separate form. Iframe具有另一种形式。 By Undocked I mean the whole iframe is copied into a new window along with the form (Form name : cform). 所谓“无靠码头”,是指将整个iframe和表单(表单名称:cform)一起复制到新窗口中。
How can I assess the hidden variables (id="r111.o1" and "r111.o2") in the Iframe from the Parent window. 如何从“父”窗口评估iframe中的隐藏变量(id =“ r111.o1”和“ r111.o2”)。
<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>
After the Iframe is undocked, 卸下iframe后,
<form method="post" action="xxx" name="pform" id="pform">
<div>
<div class="iframe">
</form>
<html><div><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">
....
how can I still be able to access the hidden variables? 如何仍然能够访问隐藏变量? Is this possible.?? 这可能吗。??
Update: I have written this JS code which I able to identity the window/iframe in both docked or undocked. 更新:我已经编写了此JS代码,可以识别停靠或未停靠的窗口/ iframe。
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;
}
All I need now is a code to iterate through the HTML elements in the object rubIframe
and rubWindow
. 我现在只需要一个代码来遍历对象rubIframe
和rubWindow
的HTML元素。 Am I going in the right path? 我走的路正确吗? Thanks in advance. 提前致谢。
var iframe = document.getElementById("yourFrameId");
var iframeContent = (iframe.contentWindow || iframe.contentDocument);
and then you can call any functions of that file like 然后您可以调用该文件的任何函数,例如
iframeContent.myfunction();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.