我尝试从另一个域访问 iframe 的内容(主体元素)。我可以访问另一个域,所以设置标题对我来说没有问题。我设置了Access-Control-Allow-Origin:*,当我检查 chrome 网络中的请求时,我Access-Control-Allow-Origin:*在响应标头中看到。
但是当我尝试这个(JS)时:
//obj = the iframe
obj.contentWindow.document.body.scrollHeight
我收到以下错误:
Blocked a frame with origin "http://mytestdomain" from accessing a frame with origin "http://192.168.0.50". Protocols, domains, and ports must match.
Uncaught TypeError: Cannot read property 'body' of undefined
我错过了什么吗?为什么Access-Control-Allow-Origin:*不工作?