两个页面:
a.htm为top页面,b.htm在iframe中.
域都为 api.adomain.com
注:所有文字说明都在注释中,只需看文字即可.
a.htm代码:
<!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=utf-8" />
<title>文件上传</title>
<script>
//页面在 api.adomain下面
/*
* 首先申明一点,
* document.domain = "api.adomain.com";
* document.domain = "adomain.com";
* 这样的设置是可以的,反之
* document.domain = "adomain.com";
* document.domain = "api.adomain.com";
* 是不行的.非ie下这样设置会保错,ie下虽然不报错但其实没成功
*
*
*/
/*
* iframe的src没有值的情况下,除IE以外,iframe的域与父页面相同, IE父页面不能设置document.domain,只要设置就跨域...(ie真是恶心)
*/
document.domain = "adomain.com";
alert(document.domain);
function init(){
document.domain = "api.adomain.com";
var i001 = document.getElementById("ifr01");
var doc = i001.contentWindow.document;
doc.domain = "api.adomain.com";
alert(doc.domain);
}
</script>
</head>
<body onload=init()>
<iframe id="ifr01" src="b.htm"></iframe>
</body>
</html>
b.htm代码:
<!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=utf-8" />
<title>�ļ��ϴ�</title>
<script>
//页面在 api.adomain.com下面
/* 如果b.htm设置为document.domain = "adomain.com"; 则在IE chrome safari下,父页面可以修改b.htm的域为 api.adomain.com(chrome和safari其实没生效) ,ff和op无法修改(无法修改貌似是比较合理的做法)
如果b.htm设置为document.domain = "api.adomain.com"; 则所有浏览器下父页面都可以将其修改为adomain.com
由此可以看出,域可以由api.adomain.com修改为adomain.com,所有浏览器都支持,而不能从adomain.com修改为api.adomain.com(部分浏览器例外,ie,chrome和safari不报错,但是修改不生效)
*/
document.domain = "api.adomain.com";
alert("iframedomain:"+document.domain);
function bcalla()
{
alert(document.domain);
}
</script>
</head>
<body>
<input type=button value="invoke" onclick="bcalla()" />
</body>
</html>
by: 天堂左我往右
分享到:
相关推荐
对于主域相同,子域不同,我们可以设置相同的document.domain来欺骗浏览器,达到跨子域的效果。 例如:我们有两个域名:www.a.com 和 img.a.com 在www.a.com下有a.html 在img.a.com下有img.json和img.html这两个文件...
iframe.document出现拒绝访问。 threw an exception of type 'System.UnauthorizedAccessException' dynamic {System.UnauthorizedAccessException}
iframe.name = 'ifr'; //iframe.setAttribute('name', 'ifr'); //这样也不行 上面两种方式都无法设置。后来找到原来也可以这样创建 JavaScript代码 var iframe = document.createElement(‘<iframe name
设置iframe的document.designMode后仅Firefox中其body[removed]为br</title> <meta charset=”utf-8″> </head> <body> <iframe frameborder=”1″ style=”height: 330px;”></...
滚动的iframe页面.rar滚动的iframe页面.rar滚动的iframe页面.rar滚动的iframe页面.rar滚动的iframe页面.rar滚动的iframe页面.rar
ajax iframe上传.rar
jquery.iframe-transport.js包
后台管理框架(iframe).zip
iframe拖动........................................
iframe高度自适应,多浏览器兼容 已测试过在ie6,7,8,firefox8,chrom15中通过
iframe.style.backgroundColor="black"; img.id = "LoadingImg"; img.style.width="219px"; img.style.height="66px"; img.style.marginTop="-33px"; img.style.marginLeft="-109.5px"; img.style.padding=...
2D WebView for WebGL Web Browser IFrame 4.2.unitypackage.zip
2D WebView for WebGL Web Browser IFrame4.1.unitypackage
飞天素材网后台管理框架模板 v2.2 iframe版.zip
后台管理模板,前后端分离 演示地址:https://demo.easyweb.vip/iframe/
基于PHP的飞天素材网后台管理框架模板 v2.2 iframe版.zip
.net iframe的简单使用 iframe实体框架的用途