You can understand the following code test as follows:
1.html:
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<Title> Non -Title Document </Title>
</head>
<body>
<div> ==================== Note: The test starts from here =============== ==== </div>
<p ID = "POX"> Used to test the element of a sub -window access to the parent window </p>
<div> ==================== iFrame segmentation line =================== = </div>
<iframe src = "a.html" frameborder = "0" id = "framea" name = "framea"> </iframe>
<iframe src = "b.html" name = "iframeb" frameborder = "0" ID = "frameb"> </iframe>
<div> ==================== iFrame segmentation line =================== = </div>
<p> Come first to demonstrate: a method or element in the parent window accessing the child window </p>
<p> Summary: The method of visiting the sub -window of the parent window adopts a different way and the element </p>
<input type = "Button" onClick = "Framediv ()" Value = "A certain element in the parent window access the element" /> /> />
<input type = "Button" onClick = "Framefun ()" Value = "A method of accessing the parent window access" /> /> />
<script type = "text/javascript">
// Sub -window access to the parent window method
Function testp (ss) {
alert (ss)
}
// Get the element of iframe
function getiframe (ID) {
Return document.GetelementByid (ID) .ContentWindow.document;
}
// Father window access the sub -window element
function framediv () {
Getiframe ("Framea"). GetelementByid ("OOXX"). Style.backgroundcolor = "#F00"
//window.frames ["iframea" ].GetelementByidmaidmaidmaidmaidmaids.
}
// Father window access the sub -window method
function framefun () {
//getIFRAME="Frameb").getsfun () ;// Can't access a method in this form in this form
// window.frames ["iframeb"]. Getsfun ();
alert (window.frames ["iframeb"]. Getsfun ());
}
</script>
</body>
</html>
a.html
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<Title> Non -Title Document </Title>
</head>
<body>
<div ID = "ooxx"> Used to test a certain element in the parent window to access a certain element in the sub -window </div>
<p ID = "DivoOXX"> Used to test a certain element in the Window B to access the window A </p>
<p> 1. Sub -window iframea access a certain element in the parent window </p>
<input type = "Button" Onclight = "Frametopdiv ()" Value = "Sub -window to access a certain element in the parent window" /> />
<input type = "Button" Onclick = "Frametopfun ()" Value = "Small Window to Access with the parent window" /> />
<script type = "text/javascript">
// Sub -window access a certain element in the parent window
Function Frametopdiv () {
Parent.document.GetelementByid ("Pox"). Style.color = "#FFF";
Parent.document.GetelementByid ("Pox"). STYLE.BACKGROUNDCOLOR = "#F0A0F0"
}
// Sub -window access to the parent window method
Function Frametopfun (SS) {
parent.testp ("ssss");
}
// The method used to test iframeb access
Function testba () {)
Alert ("Method for testing iframeb access")
}
</script>
</body>
</html>
B.html
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html; charset = gb2312" /> />
<Title> Non -Title Document </Title>
</head>
<body>
<p> Two: Test a method or element between the test sub -windows </p>
<input type = "Button" Value = "Sub -window B access a certain element in the sub -window" onClick = "frametframediv ()" /> />
<input type = "Button" value = "Sub -window B visit a method of Sub -window A" OnClick = "Frametframefun ()" /> />
<script type = "text/javascript">
// Sub -window B access to a certain element in the sub -window A
Function FrametframeDiv () {{
//parent.document.GetelementById.com
//parent.documenT.GetelementById.com
var _bFrame = Parent.getiframe ("Framea"); // The method of visiting the father window in the sub -window
_BFRAME.GetelementByid ("Divooxx"). STYLE.COLOR = "#A0C0F0";
_BFRAME.GetelementByid ("DivooXX"). STYLE.BackgroundColor = "#000";
}
// Small Window B access to a method of Sub -window A
Function Frametframefun () {{
window.parent.frames ["framea"]. testba ();
}
</script>
<script type = "text/javascript">
function getsfun () {
Return "ssssssss";
}
// getfun ()
</script>
</body>
</html>