获取一个隐藏字段从IFRAME放进容器页面 [英] Getting a hidden field from an Iframe into container page
问题描述
我有一个包含一个IFRAME的ASP页。我会打电话给它的主页。我需要一次的iframe加载完成后在主要页面设置的隐藏字段的值。 iframe的是,也可以是其在Page_Load期间设置的隐藏字段的ASP页。然后,它需要这个值传递到一个隐藏领域的主要页面上。
我在调用主框架JavaScript方法的iframe页面在onload弯。我不得不把延迟在,因为它不能以其他方式找到他们就解决了一些Telerik控制功能。看来这个页面还没有完成初始化。
问题:
有没有更好的方式来做到这一点?
是否有一个页面就绪事件?
有没有得到这些页面同步的,所以我不需要时间延迟的方法?
Thansks,
布赖恩
在的iframe页面我
的window.onload = doLoad; 功能doLoad(){
window.parent.SetHitCount(的document.getElementById(<%= hdnHitCount.ClientID%GT;值));
返回;
}
在主网页,我有这个JavaScript函数:
//从文件的iframe称为设置命中计数
功能SetHitCount(计数){
变种hdnHitCount =的document.getElementById(&下;%= hdnHitCount.ClientID%gt;中)
hdnHitCount.value =计数;
//工具栏中的设置。需要一个延迟,所以这个Telerik控制将准备
window.setTimeout(函数(){
变种工具栏= $查找(&下;%= RadToolBarDocument.ClientID%gt;中);
如果(工具栏!= NULL){
VAR键= toolbar.findItemByValue(NumberOfHits);
button.set_text(&下;%= Resources.Review_Document.Hits%gt;中+ hdnHitCount.value);
}
},1000);
}
这似乎自从被获得的 hdnHitCount
值喜欢你的问题无关的IFRAME,用没有问题。
相反,你有一个时机的问题 - 当值的控制并不总是可用
。硬codeD超时并不是一个很好的解决方案。如果控制初始化比第二个需要更长的时间(例如在较慢的机器/连接)?
要做到这一点是建立一个体系,其中两个控制初始化和 SetHitCount
功能都将检查其他已经发生了正确的方法:
- 如果在
SetHintCount
运行时,可调节,运行你的逻辑,否则,保存命中次数一些变量 - 如果当控件初始化设置了该变量,从填充它的值控制。否则,
SetHitCount
尚未执行,当它将填充控制。
I have an ASP page that contains an iframe. I'll call it the main page. I need to set a hidden field's value in the main page once the iframe has finished loading. The iframe is an ASP page that has a hidden field that is set during its page_load. It then needs to pass this value into a hidden field on the main page.
I have an onLoad hander in the iframe page calling a javascript method in the main frame. I had to put a delay in the function where it addresses some telerik controls because it couldn't find them otherwise. Seems that the page hasn't finished initializing.
Questions: Is there a better way to do this? Is there a "page is ready" event? Is there a way to get these pages synched up so I don't need time delays?
Thansks, Brian
In the iframe page I do
window.onload = doLoad;
function doLoad() {
window.parent.SetHitCount(document.getElementById("<%=hdnHitCount.ClientID %>").value);
return;
}
In the main page, I have this javascript function:
// called from document iframe to set the hit count
function SetHitCount(count){
var hdnHitCount = document.getElementById("<%=hdnHitCount.ClientID %>")
hdnHitCount.value = count;
// set in the toolbar. needs a delay so the telerik controls will be ready
window.setTimeout(function() {
var toolbar = $find("<%=RadToolBarDocument.ClientID%>");
if (toolbar != null) {
var button = toolbar.findItemByValue("NumberOfHits");
button.set_text("<%= Resources.Review_Document.Hits %>" + hdnHitCount.value);
}
}, 1000);
}
It seems like your problem has nothing to do with the IFrame, since the hdnHitCount
value is being obtained with no problem.
Rather, you have a timing issue - the control is not always available when the value is.
The hardcoded timeout is not a good solution. What if the control initialization takes longer than a second (for example on slower machines/connections)?
The right way to do it is to set up a system where both the control initialization and the SetHitCount
function will both check if the other has already happened:
- If when
SetHintCount
is run, the control is available, run your logic, otherwise, save the hit count to some variable - If when the control is initialized this variable is set, populate the control from its value. Otherwise,
SetHitCount
has not executed yet and will populate the control when it does.
这篇关于获取一个隐藏字段从IFRAME放进容器页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!