码迷,mamicode.com
首页 > Web开发 > 详细

js父页面使用iframe中的函数

时间:2016-01-09 12:08:47      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

js父页面使用iframe中的函数:
iframe是非常常用的一个html元素,如果在父页面中使用子页面的方法应该怎么写呢,下面就做一下简单的介绍。
一.父页面代码:

 

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<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>

 

二.iframe中的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>iframe代码-蚂蚁部落</title>
<script type="text/javascript">
function childFunction() 
{
  alert(function in child);
}
function callParent() 
{
  parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>

上面两个代码可以在父页面和子页面对对方的函数进行相互调用,比较简单,不多介绍了。
如有任何问题可以跟帖留言。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=9371

更多内容可以参阅:http://www.softwhy.com/javascript/

 

js父页面使用iframe中的函数

标签:

原文地址:http://www.cnblogs.com/softwhy/p/5115598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!