【发布时间】:2014-09-19 06:55:28
【问题描述】:
我有这种情况,我有一个父窗口(表单名称:pform),单击父窗口上的按钮,我向用户显示一个 iframe。 Iframe 最初是父窗口的一部分,但有一个工具可以取消 Iframe。 Iframe 有一个单独的表单。取消停靠是指整个 iframe 与表单一起复制到一个新窗口中(表单名称:cform)。
如何从父窗口评估 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>
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">
....
我怎样才能仍然能够访问隐藏变量?这可能吗??
更新: 我已经编写了这个 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;
}
我现在只需要一个代码来遍历对象rubIframe 和rubWindow 中的HTML 元素。我走在正确的道路上吗?
提前致谢。
【问题讨论】:
-
你检查过这个帖子stackoverflow.com/questions/478078/… 吗?
-
@YatinMistry 感谢您的链接。我没有提到那个。我尝试了链接中的解决方案。它在窗口停靠时工作。当窗口未停靠时,我收到此错误。在 FF firebug 中:TypeError:
ifr is null; var ifrDoc = ifr.contentDocument || ifr.contentWindow.document; -
发布您的更新代码
标签: javascript jquery forms