【发布时间】:2019-04-09 15:54:31
【问题描述】:
我有一个安装了多个 WooCommerce 的 Wordpress 多站点。我正在尝试通过 iFrame 获取安装过程中所有区域的仪表板报告:
- zh.foo.com
- au.foo.com
- eu.foo.com
等
在主仪表板页面上,我使用以下代码注入所需的 iFrame:
jQuery(document).ready(function($) {
/*If the user is on the main dashboard...*/
if(window.location.href.indexOf("https://foo.com/wp-admin/network/") > -1) {
console.log('Admin Dashboard - Activating global iFrame stats');
/*Create area for iFrames*/
$('#dashboard-widgets').after('<div class="iframe-container"><strong>Cross Network Stats (US, UK, AU, EU)</strong></div>');
/*United States*/
/*Add US iFrame (on same domain - working)*/
$('.iframe-container').append('<div><strong style="font-size: 2em;">United States:</strong><br><br><iframe src="https://foo.com/wp-admin/edit.php?post_type=shop_order" width="100%" height="450px"></iframe></div>');
/*United Kingdom*/
/*Add UK iFrame (on subdomain - not working)*/
$('.iframe-container').append('<div><strong style="font-size: 2em;">United Kingdom:</strong><br><br><iframe src="https://en.foo.com/wp-admin/edit.php?post_type=shop_order" width="100%" height="450px"></iframe></div>');
}
});
第一个 iFrame 按预期工作,但第二个不按预期工作,因为它位于 iFrame 中并会产生 X-Frame 安全错误:
X-Frame-Options 拒绝加载: https://en.foo.com/wp-admin/edit.php?post_type=shop_order 没有 允许跨域框架。
我已经读到可以通过使用“document.domain”来避免这种情况。因此,我在全局管理页脚的页脚中注入了以下代码:
echo '<script>document.domain = "foo.com";</script>';
但是,我仍然遇到与以前相同的问题。
通过 jQuery 调用 iFrame 时是否需要将 document.domain 作为 javascript 函数触发?
【问题讨论】:
-
很久没有和
document.domain打交道了,这可能很棘手......如果它仍然有效的话。总是必须立即宣布……在其他一切之前。可能还会阅读 X-Frame-Options -
谢谢,我已将脚本置于所有其他脚本之上,但仍然出现相同的错误。
标签: javascript wordpress iframe x-frame-options