我有类似的东西:
<iframe src="https://foo.com"></iframe>
我希望https://foo.com重定向到https://bar.com。
我已经尝试过服务器端重定向(https://foo.com返回302)和客户端重定向(foo.com包含一个window.location.href = https://bar.com
的脚本),但却阻止了跨域浏览器发送帖子消息时出错:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://foo.com') does not match the recipient window's origin ('https://bar.com').
iframe中的重定向是否可能?
答案 0 :(得分:0)
是的,您可以重定向。
听起来你也成功了。
...但是如果您重定向到其他来源,那么您将重定向到其他来源。任何跨源请求都需要授予新原点的权限。
从http://foo.com/
重定向到http://bar.com
并未授予bar.com
授予foo.com
的所有权限。
如果您要将postMessage
发送到bar.com
,那么您需要将该消息标记为预期的来源。