首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

关于iframe子页面调用父窗口js函数的有关问题,请问

2013-01-21 
关于iframe子页面调用父窗口js函数的问题,请教这个是父窗口代码:htmlheadscript typetext/javascri

关于iframe子页面调用父窗口js函数的问题,请教
这个是父窗口代码:
<html>
<head>
<script type="text/javascript">
function __change(){
console.log('__change()')
}
</script>
</head>
<body>
<iframe src="A/A.html">1</iframe>
</body>
</html>

A.html的代码:
<html>
<head>
<script>
function test(){
console.log('A')
//window.parent.document
// self.parent.__change();
window.parent.__change(); 
// window.parent.__change()
}
</script>
</head>
<body>
<input type="button" onclick="test()" value="A"/>
</body>
</html> 

我在点击按钮A的时候  提示这个错误:
Unsafe JavaScript attempt to access frame with URL file:///U:/js/index.html from frame with URL file:///U:/js/A/A.html. Domains, protocols and ports must match.
 A.html:8
Uncaught TypeError: Property '__change' of object [object Window] is not a function 

今天整了半天   实在是没办法了

javascript iframe function
[解决办法]
哇,这样本地的也算跨域了
你把“A.html”放到和父级页面同目录,或你架起web服务再访问 试试
[解决办法]
什么浏览器?webkit核心的如chrome本地测试访问不了iframe或者iframe访问不了parent对象的,需要搭建服务器通过http访问

本地测试用ie或者firefox:chrome浏览器iframe parent.document为undefined

热点排行