从父窗口访问子窗口控件 [英] Access Child window controls from parent window
本文介绍了从父窗口访问子窗口控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过javascript打开窗口使用window.open在该窗口中我有用户名,pwd文本框在打开时我必须向子控件发送值并提交提交我需要帮助来自某个显示始终访问被拒绝的一些代码< br $> b $ b
I am opening an window through javascript using window.open in that window i have username,pwd textboxes while opening i must send value to child controls and make submit i sumitting the code need help from some one it shows always access denied
var popUpObj;
popUpObj=window.open(FastSystemURL+"&Ran="+Math.random(),"Whatsin","height=600,width=1200,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=100,left=200",'hiddenframe');
getChildControl(uname,pwd,PartNo,CaseId,SN)
function getChildControl(uname,pwd,PartNo,CaseId,SN)
{
if(popUpObj != null && !popUpObj.closed)
{
var Childform = popUpObj.document.getElementsByTagName("form1")[0];
Childform.uname.value=uname;
Childform.password.value=pwd;
Childform.SerialNo.value=SN;
Childform.Pn.value=PartNo;
Childform.caseid.value=CaseId;
Childform.BiosVersion.value='';
Childform.btnsubmit.submit();
return false;
}
}
推荐答案
窗口消息传递( window.postMessage [ ^ ])
你可以通过Window Message Passing来做到这一点( window.postMessage [ ^ ]),当两者都在不同的域中时。
对于你的情况,父母会给孩子发一条消息,孩子会有一个听众听这个消息。
代码可能如下所示。
Window Message Passing(window.postMessage[^])
You can do this by Window Message Passing(window.postMessage[^]), when both are in different domains.
For your case, the parent will post a message to child and there will be a listener in child to listen to this message.
The code may be like below in parent.
childWindow.postMessage(message, targetOrigin);
和孩子的倾听者会是这样的。
And the listener in child will be like.
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from parent window
eventer(messageEvent,function(e) {
message = e.data; // This is the "message" passed from parent.
},false);
这可以从任何一方完成。我的意思是你也可以从孩子到父窗口进行交流。
请尝试实施...
谢谢,
Tadit
This can be done from either side. I mean you can also communicate from child to parent window.
Please try to implement...
Thanks,
Tadit
这篇关于从父窗口访问子窗口控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文