Uncaught SecurityError:无法从'HTMLIFrameElement'中读取'contentDocument'属性:阻止具有原点“http://www.bhjk.com”的框架访问具有原点“http://c.betrad.com”的框架。协议,域和端口必须匹配。
Heres'我的代码:
getBody: function(slot) {
//Here I'm checking if div id is null to avoid type errors later
if(document.getElementById(this.getDomId(slot)) != null){
var iframe = document.getElementById(this.getDomId(slot)).getElementsByTagName('iframe')[0];
console.log("iframe is:");
console.log(iframe);
}
else{
return false;
}
console.log("now checking for same origin policy");
console.log(iframe.contentDocument.body);
if(iframe) return iframe.contentDocument.body;
return false;
},
更具体地说,以下陈述给我带来了问题。 Wahts是处理上述错误的最佳方法吗?
if(iframe) return iframe.contentDocument.body;
答案 0 :(得分:0)
也许有一个try-catch块:
try{
return iframe.contentDocument.body;
}catch(exception){
console.log(exception);
return false;
}