【问题标题】:GWT Blocked a frame with origin "http://localhost" from accessing a cross-origin frameGWT 阻止源为“http://localhost”的框架访问跨域框架
【发布时间】:2018-05-31 10:04:17
【问题描述】:

我想允许用户输入他们的网址并在 iframe 中浏览。 在他们点击确认按钮后,我会从 iframe 中获取浏览的 url。

IFrameElement frame = IFrameElement.as(DOM.createIFrame());
frame.setSrc("http://www.example.com"); //set the url of user enter
VerticalPanel ver = new VerticalPanel();
ver.getElement().appendChild(frame);

// After they click the confirm button, get the url from iframe
Window.alert(frame.getContentDocument().getURL());

但我从 iframe 获取 url 后出现错误

异常:com.google.gwt.event.shared.UmbrellaException:异常 捕获:(SecurityError):阻止了具有原点的帧 “http://localhost”访问跨域框架。

【问题讨论】:

    标签: javascript iframe gwt


    【解决方案1】:

    简而言之:你不应该这样做,你也不能这样做。


    第一:

    某些页面的作者根本不想让他们的页面显示在框架中。以 Facebook 为例,您将获得:

    拒绝在框架中显示“https://www.facebook.com/”,因为它将“X-Frame-Options”设置为“拒绝”。

    还可以检查(使用脚本)页面是否在框架中并“突破”并进入主窗口,http://www.interia.pl/ 就是一个例子。

    因此,有些页面无法在框架中显示。


    第二:

    阅读Same Origin Policy (SOP)

    简单地说,SOP 规定网页上运行的 JavaScript 代码不得与任何非来自同一网站的资源进行交互。存在此安全策略的原因是防止恶意 Web 编码人员创建窃取 Web 用户信息或损害其隐私的页面。虽然非常必要,但这项政策也有让 Web 开发人员生活困难的副作用。

    【讨论】:

      猜你喜欢
      • 2019-02-05
      • 2017-06-25
      • 2019-01-19
      • 2018-12-14
      • 1970-01-01
      • 2016-09-28
      • 2014-09-25
      相关资源
      最近更新 更多