JS 报错 没有权限

没有权限是因为js脚本有“不能跨域访问”,只能在相同域访问的规定!只需在脚本加入document.domain="域名"即可

以下是测试代码:

main.html

<html>
<head>
</head>
<body style="margin:0px">
<iframe src="left.html" width="49%" />
<iframe src="right.html" width="50%" />
</body>
</html>

left.html

<html>
<head>
<script type="text/javascript">
//document.domain="192.168.153.68";
function leftfun()
{
alert("left");
}
function test()
{
parent.frames[1].rightfun();
}
</script>
</head>
<body>
<input type="button" onclick="test()" value="call rightframe function" />
</body>
</html>

right.html

<html>
<head>
<script type="text/javascript">
document.domain="192.168.153.68";
function rightfun()
{
alert("right");
}
function test()
{
parent.frames[0].leftfun();
}
</script>
</head>
<body>
<input type="button" onclick="test()" value="call leftframe function" />
</body>
</html>

//原文http://hi.baidu.com/cheng32/blog/item/d24d28a8670849bcca130c76.html

你可能感兴趣的:(c,function,脚本,测试,button)