手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >js实现iframe跨页面调用函数的方法
js实现iframe跨页面调用函数的方法
摘要:本文实例讲述了js实现iframe跨页面调用函数的方法。分享给大家供大家参考。具体实现方法如下:在项目中难免会遇到这样一个问题就是页面引入了...

本文实例讲述了js实现iframe跨页面调用函数的方法。分享给大家供大家参考。具体实现方法如下:

在项目中难免会遇到这样一个问题就是页面引入了IFrame并且需要父页面调用子页面函数或者子页面需要调用父页面函数。比如说:现在有两个页面parent.html和child.html。其中parent.html中含有IFrame并且IFrame指向child.html。现在需要在parent.html/child.html中调用child.html/parent.html的一个js方法。

具体的代码实现如下:

parent.html父页面:

复制代码 代码如下:<html>

<head>

<script type="text/javascript">

function parent_click(){

alert("来自父页面");

}

</script>

</head>

<body>

<input type="button" value="调用本页面函数" />

<input type="button" value="调用子页面函数" onclick='window.frames["childPage"].child_click();' />

<iframe id="childPage" name="childPage" src="inner.html" width="100%" frameborder="0"></iframe>

</body>

</html>

child.html子页面:

复制代码 代码如下:<html>

<head>

<script type="text/javascript">

function child_click(){

alert("调用的子页面函数");

}

</script>

</head>

<body>

<input type="button" value="调用父页面函数" onclick='parent.window.parent_click();' />

<input type="button" value="调用本页面函数" />

</body>

</html>

希望本文所述对大家基于javascript的web程序设计有所帮助。

【js实现iframe跨页面调用函数的方法】相关文章:

jQuery实现表格行上移下移和置顶的方法

JS实现两表格里数据来回转移的方法

JS实现简单路由器功能的方法

js实现文本框选中的方法

javascript实现动态改变层大小的方法

Javascript实现飞动广告效果的方法

javascript实时显示当天日期的方法

JavaScript实现表格点击排序的方法

javascript实现点击后变换按钮显示文字的方法

javascript实现行拖动的方法

精品推荐
分类导航