你可以另外写个独立的demo测试,你这个看错误信息说的是c.html与a.html还是不同域,但顶级域名相同(就是仅域名的后半截相同),所以需要设置document.domain现在没有用域名 两台机器都是 ip
Unsafe JavaScript attempt to access frame with URL http://172.18.88.4/lszfw/e/admin/up/parent.html from frame with URL http://172.18.88.4/lszfw/e/admin/up/agent.html#path=http://172.18.88.104:81/test3/2014-04-25/61.jpg. The frame being accessed set 'document.domain' to '172.18.88.4', but the frame requesting access did not. Both must set 'document.domain' to the same value to allow access. 单独进行测试 咋还是不行
底层的网络协议决定了,跨域操作是不可能的。
如果可能,我iframe 一个网银页面,别人输入的用户名和密码我不是就得到了?
这个和我们网上支付的流程是一样的,在银行/支付宝网关完成支付后,跳转回发起请求的商户,以便把支付结果通知商户的程序。
http://blog.csdn.net/ivyandrich/article/details/24372909
是的,现在是已经可以在 c.html中接受到b.php中传递的值了,c.html 和a.html现在在同一域下了,现在c.html怎么把值传递给a.html呢?
不能通过parent.parent操作a.html已经试过了
大概思路是 b.php中iframe加载一个与a.html同域的页面,假设是a1.html,这样a1.html中通过paren.parent可以访问到a.html的window对象,而且注意a1.html与a.html之间是没有跨域的,所以a1.html是可以操作a.html的,那么剩下的就简单了,b.php想操作a.html时只需要设置iframe的src为a1.html,并传递url参数,a1.html获得参数并调用a.html中的函数,传递参数,这样就完成了b.php对a.html的操作并传递了参数。
这就是经典的iframe跨域方式,兼容各浏览器
你可以另外写个独立的demo测试,你这个看错误信息说的是c.html与a.html还是不同域,但顶级域名相同(就是仅域名的后半截相同),所以需要设置document.domain
,完后在http://www.a.com/setHeight.html中通过parent.parent.document.getElementById去控制http://www.a.com/a.html里的iframe的高度
我是这么做的:
A.html 所在域名 www.a.com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
</head>
<body>
<iframe height='200px' id='iframe1' src="http://www.b.com/B.html"></iframe>
</body>
</html>
B.html 所在域名 www.b.com <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body style="background-color:#ccc">
<div style="height:600px;">sdfsfsssfsfs</div>
<script>
window.onload = function()
{
//先判断iframe是否存在,存在的话,删除掉先
if(document.getElementById("sheight"))
{
document.body.removeChild(document.getElementById("sheight"));
}
var iframe = document.createElement("iframe");
iframe.width='0px';
iframe.height='0px';
iframe.id='sheight';
var currentheight = document.body.scrollHeight;
iframe.src='http://www.a.com/setHeight.html#'+currentheight;
document.body.appendChild(iframe);
}
</script>
</body>
</html> setHeight.html是和a.html同一个域名下的 www.a.com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
</head>
<body>
<div></div>
<script type="text/javascript">
window.onload = function()
{
var b_iframe = parent.parent.document.getElementById("iframe1");
var hash_url = window.location.hash.split("#");
var hash_height = hash_url[1]+"px";
b_iframe.style.height = hash_height;
}
</script>
</body>
</html>
你可以另外写个独立的demo测试,你这个看错误信息说的是c.html与a.html还是不同域,但顶级域名相同(就是仅域名的后半截相同),所以需要设置document.domain现在没有用域名 两台机器都是 ip
单独进行测试 咋还是不行
去看看吧 aralejs/messenger就是根据他实现的,上面介绍的也很详细
可以去看看