Home  >  Article  >  Web Front-end  >  How to use subpages in js parent page_javascript skills

How to use subpages in js parent page_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:20:461318browse

iframe is a very commonly used html element. If you use a child page in the parent page, how should you write it? Here is a brief introduction.
1. Parent page code

<html>
<head>
<meta charset=" gb2312">
<title>父页面</title>
<script type="text/javascript">
function parentFunction() 
{
 alert('function in parent');
}
function callChild() 
{
 child.window.childFunction();
 /*
  child 为iframe的name属性值,
  不能为id,因为在FireFox下id不能获取iframe对象
 */
}
</script>
</head>
<body>
 <iframe name="child" src="./child.html" ></iframe>
</body>
</html>

2. Code in iframe

<html>
<head>
<meta charset="gb2312">
<title>iframe代码</title>
<script type="text/javascript">
function childFunction() 
{
 alert('function in child');
}
function callParent() 
{
 parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>

The above two codes can call each other's functions on the parent page and the child page. It is relatively simple and will not be introduced in detail.
I hope this article will help you learn JavaScript programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn