Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 阻止具有原点的帧如何修复_Javascript_Php_.htaccess - Fatal编程技术网

Javascript 阻止具有原点的帧如何修复

Javascript 阻止具有原点的帧如何修复,javascript,php,.htaccess,Javascript,Php,.htaccess,用原点https://xxxx从使用原点访问帧https://xxx。协议、域和端口必须匹配 我需要这个设置才能工作,并且我可以访问这两个域(2个不同的域) 我怎样才能摆脱这个 我试着在页面上放置php标题,在那里放置iframe: header("Access-Control-Allow-Origin: https://domain_the_iframe_is_placed"); 以及在htaccess中: <IfModule mod_headers.c> Header

用原点
https://xxxx
从使用原点访问帧
https://xxx
。协议、域和端口必须匹配

我需要这个设置才能工作,并且我可以访问这两个域(2个不同的域)

我怎样才能摆脱这个

我试着在页面上放置
php标题
,在那里放置
iframe

header("Access-Control-Allow-Origin: https://domain_the_iframe_is_placed");
以及在htaccess中:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

标题集访问控制允许原点“*”
我能做什么

这是iframe页面,它位于另一个域(y.com)上,但位于x.com上

  parent.document.getElementById('accoxxation').value='<?=$_POST['account_verification']?>';
  parent.document.getElementById('accxx').value='<?=$_POST['account_number']?>';
  parent.document.getElementById('accxxonth').value='<?=$_POST['account_month']?>';
  parent.document.getElementById('accxxxr').value='<?=$_POST['account_year']?>';

  parent.document.getElementById('gatewayProcessor').submit();
parent.document.getElementById('accountxation')。值=“”;
parent.document.getElementById('accxx')。值=“”;
parent.document.getElementById('acxxonth')。值=“”;
parent.document.getElementById('acxxxr')。值='';
parent.document.getElementById('gatewayProcessor').submit();

允许源将允许称为CORS的服务器请求,而不是帧间连接。尝试与Windows messagging进行通信,它就是为此而设计的。
例如:

家长:

myFrame.contentWindow
        .postMessage("STRING", myFrame.src);
我的框架:

window.addEventListener("message", function (event) {
    // Security: Validate message origin
    if (event.origin !== myVerifiedOrigin) {
        return;
    }
    console.log(event.data);
});

禁止从其他来源访问帧。您可以在浏览器设置的深度中进行更改。我认为这不是个好主意。这是安全问题。如果您可以控制这两个源,则可以使用postMessage与抛出帧进行通信


默认情况下,您不能/不应该这样做,但根据本网站

这是“同一原产地”政策中的一个小例外

如果windows共享同一个二级域,例如john.site.com、peter.site.com和site.com(因此它们的公共二级域是site.com),则可以将它们视为来自“同一来源”

要使其正常工作,所有此类页面(包括site.com上的页面)都应运行以下代码:

document.domain = 'site.com';

就这些。现在他们可以无限制地进行互动。同样,这只适用于具有相同二级域的页面。

addEventListener与我给出的示例有什么关系?你能给我举个例子说明你的意思吗?应该是相反的。从不同域的iFrame提交到我这边(parent.window)谢谢,我已经接受了你的答案并发布了解决方案。