Error: Permission denied to access property '$' - iFrame
Error: Permission denied to access property '$' - iFrame
我在 Bootstrap 模式中使用 iFrame 时遇到问题。它是一个新闻系统,我从另一个子域的 iFrame 加载新闻内容。一切正常,如果用户单击任何新闻项目中的图像,我想在 Parent Window 中打开一个灯箱 (Fancybox)。这通常不是问题,我正在使用这样的东西:
// so i know its an Popup / has an iFrame (class Popup is when it is opened in an BS Modal) - otherwise ill go to my news size and show the article there.
$('a[rel="lightbox"]').click(function(e) {
e.preventDefault();
var link = $(this).attr('href');
if ($(this).closest('body').hasClass('popup')) {
parent.$.fancybox({
// this is without any popup
$.fancybox({
href: link,
...
我的图像在另一个域上 - 比如 static.site.com。当我去 news.site.com - 并打开一个弹出窗口(现在它来自同一个域) - 然后单击一个图像 - 一切都很好,
parent.$
工作正常。
但是,当我从主站点 (www.site.com) 打开模态框(内容来自 news.site.com)然后单击图像 (static.site.com) 时,会出现以下内容错误:
Error: Permission denied to access property '$'
我已经允许 PHP Header 从另一个子域加载内容 - 但我仍然遇到此错误。
我是否需要使用 JSONP(将页面内容加载为 HTML?)- 还是有其他更简单的解决方案?
您需要将两个域都设置为 JavaScript 中的 same top level domain:
A page may change its own origin with some limitations. A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks.
因此,如果您有 static.example.com
和 news.example.com
,您应该在尝试任何跨框架访问之前将此 JavaScript 包含到 运行:
document.domain = 'example.com';
您将需要 运行 在两个 windows 中使用此代码。
我在 Bootstrap 模式中使用 iFrame 时遇到问题。它是一个新闻系统,我从另一个子域的 iFrame 加载新闻内容。一切正常,如果用户单击任何新闻项目中的图像,我想在 Parent Window 中打开一个灯箱 (Fancybox)。这通常不是问题,我正在使用这样的东西:
// so i know its an Popup / has an iFrame (class Popup is when it is opened in an BS Modal) - otherwise ill go to my news size and show the article there.
$('a[rel="lightbox"]').click(function(e) {
e.preventDefault();
var link = $(this).attr('href');
if ($(this).closest('body').hasClass('popup')) {
parent.$.fancybox({
// this is without any popup
$.fancybox({
href: link,
...
我的图像在另一个域上 - 比如 static.site.com。当我去 news.site.com - 并打开一个弹出窗口(现在它来自同一个域) - 然后单击一个图像 - 一切都很好,
parent.$
工作正常。
但是,当我从主站点 (www.site.com) 打开模态框(内容来自 news.site.com)然后单击图像 (static.site.com) 时,会出现以下内容错误:
Error: Permission denied to access property '$'
我已经允许 PHP Header 从另一个子域加载内容 - 但我仍然遇到此错误。
我是否需要使用 JSONP(将页面内容加载为 HTML?)- 还是有其他更简单的解决方案?
您需要将两个域都设置为 JavaScript 中的 same top level domain:
A page may change its own origin with some limitations. A script can set the value of document.domain to a subset of the current domain. If it does so, the shorter domain is used for subsequent origin checks.
因此,如果您有 static.example.com
和 news.example.com
,您应该在尝试任何跨框架访问之前将此 JavaScript 包含到 运行:
document.domain = 'example.com';
您将需要 运行 在两个 windows 中使用此代码。