How do Js ifame and functions in the parent window interact?

Source: Internet
Author: User

Page A contains an iframe. Some html code is as follows:

[Html]
<Div> <iframe name = "ifm" width = "100%" height = "829" id = "ifmApp" src = "B. asp? Co = 1 & tp = 5 & ut = 1 & id = & gd = 11 & gm = 1 & ar = 2 & sv = 0 "frameBorder =" 0 "marginWidth =" 0 "marginHeight =" 0 "scrolling =" no "> </div>
 
A page contains the following js scripts:

Www.2cto.com
[Javascript]
Var System = {
CloseFrame: function (){
Try {
Var frames = document. getElementById ("ifmApp ");
Var AppHelper = frames. contentWindow. AppHelper;
If (AppHelper! = Null & typeof (AppHelper) = "object" & typeof (AppHelper. CloseQuery) = "function "){
If (! AppHelper. CloseQuery () return;
}
} Catch (e ){
}
System. Close ();
},
Close: function (){
Document. body. removeChild (ifrm );
}
};

The B. asp page corresponding to iframe src, with js functions:

[Javascript]
Var Apphelper = {
CloseQuery: function (){
If (val = "1") return true;
Return false;
},
Close: function (){
If (parent! = Null & typeof (parent) = "object "){
Var System = parent. System;
If (System! = Null & typeof (System) = "object "){
If (System. Close! = Null & typeof (System. Close) = "function "){
System. Close ();
Return;
}
}
}
}
};

Parent page A, calling its own System. CloseFrame to call the function Apphelper. CloseQuery in ifrme
In Ifame, the B page calls the System. Close function in the parent window by calling its Apphelper. Close function.

Of course, there is A premise to implement such A simple call, that is, A and B need to be in the same domain.

From the pure soul

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.