javascript - 不安全的 JavaScript 尝试使用 URL 访问框架 - 在同一域中

标签 javascript cross-domain

我试图从 iFrame 访问父窗口的 URL,但我的服务器出现错误:

Unsafe JavaScript attempt to access frame with URL http://www.domain.com/folder/ from frame with URL http://www.domain.com/folder/file.html. The frame being accessed set 'document.domain' to 'domain.com', but the frame requesting access did not. Both must set 'document.domain' to the same value to allow access.

我在同一个域中,所以我不明白为什么会出现此错误。 供您引用,在本地主机上一切正常。

感谢您的帮助。

最佳答案

好的,我找到了解决方案。 我输入了这段代码并且有效:

document.domain = 'domain.com';

关于javascript - 不安全的 JavaScript 尝试使用 URL 访问框架 - 在同一域中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14592685/

相关文章:

javascript - 如何在 mvc 5 中创建字符串数组

javascript - 如何在大型 vue.js 应用程序中构建组件?

javascript - 传递 "this"作为参数

javascript - 如何将数组中的所有其他元素加倍?

javascript - MooTools CORS 请求与 native Javascript

javascript - 多次 API 调用后 Angular 执行函数

javascript - 跨域请求的 Cookie

tomcat - 跨域脚本启用

ajax - canary --disable-web-security 不再适用于 AngularJS 项目中的 ajax 请求

safari - 阻止来源为 "https://tpc.googlesyndication.com"的框架访问来源为 ""的框架。协议(protocol)、域和端口必须匹配