跨域问题的解决思考
1.www.a.com
a:a.com是主域
b:www.a.com是二级域名
c:对于主域相同,但是二级域名不同的问题,解决办法:通过设置document.domain来解决
1:在www.a.com的a.html中设置documen.domain = 'a.com';然后通过a.html文件中创建一个iframe,链接到b.html中,插入到本界面,然后处理
document.domain = 'a.com';
var ifr = document.createElement('iframe');
ifr.src = 'http://script.a.com/b.html';
ifr.style.display = 'none';
document.body.appendChild(ifr);
ifr.onload = function(){
var doc = ifr.contentDocument || ifr.contentWindow.document;
// 在这里操纵b.html
alert(doc.getElementsByTagName("h1")[0].childNodes[0].nodeValue);
};
2.在script.a.com的b.html中设置documen.domain = 'a.com'
document.domain = 'a.com';
浙公网安备 33010602011771号