假如
在网站www.A.com下通过iframe或ajax调用www.B.com下的内容时,默认情况下IE会阻止www.B.com写任何Cookie
//www.B.com里的被调用的页面需要写P3P头,从而解除IE对写Cookie的阻止
context.Response.AddHeader("P3P", "CP=CAO PSA OUR"); //www.A.com里通过ajax调用www.B.com里的内容时,是跨域访问,需要使用jsonp,为配合其工作需要添加下面两句,生成jsonp返回
context.Response.ContentType = "text/plain";
context.Response.Write(string.Format("{0}('OK')", context.Request["callback"]));
//jsonp调用进行跨域访问
jQuery.ajax({
url: url,
type: 'GET',
data: data,
dataType: 'jsonp',
success: function (data) {
window.location.href = toURL;
}
});
在网站www.A.com下通过iframe或ajax调用www.B.com下的内容时,默认情况下IE会阻止www.B.com写任何Cookie
//www.B.com里的被调用的页面需要写P3P头,从而解除IE对写Cookie的阻止
context.Response.AddHeader("P3P", "CP=CAO PSA OUR"); //www.A.com里通过ajax调用www.B.com里的内容时,是跨域访问,需要使用jsonp,为配合其工作需要添加下面两句,生成jsonp返回
context.Response.ContentType = "text/plain";
context.Response.Write(string.Format("{0}('OK')", context.Request["callback"]));
//jsonp调用进行跨域访问
jQuery.ajax({
url: url,
type: 'GET',
data: data,
dataType: 'jsonp',
success: function (data) {
window.location.href = toURL;
}
});
当页面存在iframe时,想要获取iframe框架里面的cookie,就要在iframe相应的动态页面里添加P3P Header信息,否则在IE下获取不到。因为IE有安全策略,限制頁面不保存第三方cookie(注:当前访问页面为第一方cookie,第三方cookie就是当前网页以外的其他网页的cookie)。
ie8里面貌似不认这个p3p的头部的,帖子链接的文件里面提到了XDomainRequestAllowed设置为1 这个,但是我设置了在ie8中还不是不管用
Response.AddHeader("P3P", "CP=CAO PSA OUR");或者在Window服务中将ASP.NET State Service 启动。
不知道版主你亲自实验过了没,至少我加上
p3p的头部在ie8浏览器上测试还不是行的哦,
我查看资料说P3p是支持6,7版本的,ie8并不支持呢
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312"/>
<meta http-equiv="Content-Script-Type" Content="text/javascript"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<meta http-equiv="Author" content="Langtse"/>
<title>使用Object实现Iframe功能</title>
<style>
#iframe{border:1px solid silver;width:640px;height:480px;padding:2px;}
object{border:1px solid silver;width:638px;height:478px;}
</style>
<script>
function btnClick(sUrl){
var ifra=document.getElementById("iframe");
ifra.innerHTML='<object id="obj1" type="text/html" data="'+sUrl+'"></object>';
}
</script>
<script>
</script>
</head>
<body>
<form>
<input name="url" size="60" type="text" value="login.html" />
<input type="button" onClick="btnClick(this.form.url.value);" value="打开网页" />
</form>
<div id="iframe"><p>使用Object实现Iframe功能</p>这里显示你打开的页面内容</div>
</body>
</html>