在 iOS 中从 iframe 重定向父页面

Redirect parent page from iframe in iOS

我正在将 iFrame 嵌入外部支付提供商,在用户完成他们的步骤后,用户将被重定向到我的域。 我现在正尝试将父页面重定向到位于我的域中的另一个页面,如下所示:

嵌入在 mydomain.com

上的 iFrame
<iframe src="example.com/payment" sandbox="allow-top-navigation allow-forms allow-scripts"></iframe>

重定向父页面的代码

window.top.location.href = "mydomain.com";

在 iOS 的 Safari 上,我现在得到:SecurityError:DOM 异常 18:试图突破用户代理的安全策略。

即使我在我的沙箱参数中使用了 allow-top-navigation,这是否是预期的行为? 如果是这样,是否有任何现有的解决方法?

我自己找到了答案。 我的 iframe 沙盒属性缺少:allow-same-origin 参数

工作示例

<iframe src="example.com/payment" sandbox="allow-same-origin allow-top-navigation allow-forms allow-scripts"></iframe>

说明

据我了解,问题在于重定向: example.com/paymentmydomain.com 这会被某些浏览器阻止。 可悲的是,我没有找到关于为什么阻止此特定重定向的明确解释。 似乎与:https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

有关