【问题标题】:Cannot Open Link Inside Iframe无法在 iframe 中打开链接
【发布时间】:2018-06-18 16:05:33
【问题描述】:

我知道这个问题已经在这里被问过好几次了,但我无法找到完美的工作解决方案。

我正在尝试将我的 Angular 4 应用程序 URL 嵌入到 Iframe 中:

<html>
    <body>
        <iframe src="http://localhost:4300/login" height="200"></iframe>
    </body>
</html>

但是,当我打开此页面时,我看不到我的应用程序正在运行。我发现这个问题与 CORS 有关,但我无法找出确切的解决方案。

在我的浏览器控制台上,我收到以下错误:

ERROR DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    at t._loadLevel (http://localhost:4300/vendor.0a81172ada1f31f3dc62.bundle.js:1:927903) 

现有的类似问题:

Link inside iframe wont work

How to open a iframe link within the same iframe?

how to resolve iframe cross domain issue

https://github.com/apollographql/apollo-client-devtools/issues/106

https://github.com/disconnectme/disconnect/issues/315

https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

Iframe in Chrome error: Uncaught SecurityError: Failed to read the 'sessionStorage' property from 'Window'

请帮帮我。

【问题讨论】:

  • “我知道这个问题已经在这里被问过好几次了……”,你能发布一两个这些问题的网址吗?我想看看这是否是一种常见做法及其背后的原因。
  • @zer00ne 更新有问题
  • 我之所以困惑是因为两个页面在同一个站点上,对吗?
  • @zer00ne 是的,我从堆栈溢出中得到了这个信息,只有你能帮助我,然后它会很棒
  • @zer00ne 我更新了一些链接。

标签: angular iframe


【解决方案1】:

冒着听起来过于简单化的风险,您是否尝试过在您使用的任何浏览器中启用第三方 Cookie?

我在 iframe 中使用 localStorage 和 Angular 应用程序时遇到了一些问题,但最终可以正常工作。

例如,在 Chrome 中:

https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

【讨论】:

  • 我不强制使用更改浏览器的设置。如果我们能务实地处理,那就太好了。
  • 我会检查一下这实际上是否是本地问题。如果是这样,我会确保您的用户会遇到问题。对我来说,我的本地设置是这样设置的,但没有听到任何用户对此问题的窥探。我认为浏览网页几乎不可能将所有 cookie 都屏蔽掉,而且它不应该是默认的浏览器设置。
  • 我不确定,但我的 cookie 选项已启用,但阻止第三方 cookie 已禁用。
  • 还有一件事要尝试,如果您使用的是 Chrome,cookie 的最高安全设置为:“允许网站保存和读取 cookie 数据”。确保已启用此功能。如果这不起作用,那么我在这个问题上的经验是有限的。你试过不同的浏览器吗?如果它们都坏了,或者其中一些可以工作,那至少可以稍微缩小问题的范围。
猜你喜欢
  • 2012-08-15
  • 2022-09-23
  • 2010-12-14
  • 2018-01-30
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多