gpt4 book ai didi

jquery - $ ('iframe' ).content() : Cannot get CORS passed

转载 作者:行者123 更新时间:2023-12-01 01:45:42 24 4
gpt4 key购买 nike

我在 http://mysite.dev:3000 上有一个 iframe,此页面上的脚本会将 iframe src 属性设置为 http://mysite.dev:5000/somepage.html.

加载 iframe 后,我想使用此脚本访问其内容(在 http://mysite.dev:3000 上):

$('iframe').load(function() {
$('iframe').contents();
});

我总是收到错误:

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin.

尽管如此,http://mysite.dev:5000/somepage.html 的响应 header 遵循 CORS 准则:

Accept-Ranges:bytes
access-control-allow-credentials:true
access-control-allow-headers:Authorization, X-Requested-With, Content-Type, Origin, Accept
access-control-allow-methods:GET,PUT,POST,DELETE,OPTIONS
access-control-allow-origin:*
Cache-Control:public, max-age=0

我读了几个关于 SO 的问题并遵循它们,但仍然不起作用。

最佳答案

cors header 不适用于 iframe。您需要使用 postMessage 方法来跨域传输数据。请参阅Cross domain iframe issue

关于jquery - $ ('iframe' ).content() : Cannot get CORS passed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24862061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com