Stumbleupon Iframe 中的站点块 javascript

Site blocks javascript in Stumbleupon Iframe

我正在尝试将我网站 www.drewgl.com 中的一些页面添加到 stumbleupon。它非常依赖javascript。当我通过 stumbleupon 查看我的网站时,javascript 被阻止。具体来说,我看到错误:

Uncaught SecurityError: Blocked a frame with origin "http://www.drewgl.com" from accessing a frame with origin "http://www.stumbleupon.com". Protocols, domains, and ports must match

我正在使用 rails 4 部署到 heroku。我将我的 X 框架选项设置为允许所有。我通读了这里的答案: SecurityError: Blocked a frame with origin from accessing a cross-origin frame 似乎解决此问题的唯一方法是使用 window.postmessage 在两个页面之间发送消息。但是,要做到这一点,您必须同时拥有这两个页面。

当然,Stumbleupon 无法满足这种情况,那么我该如何解决这个问题呢?

编辑:我刚刚下载了 chrome 的 stumbleupon 工具栏。这样做之后,我不再收到上述错误消息。无论哪种方式,我仍然想为没有工具栏的绊脚石解决这个问题。

想通了。如果有人好奇,您不能从 iframe 中访问当前路径。这段代码导致了问题:

//     if (top.location.pathname === '/users/sign_in')
// {
//     $('#login').modal('show');
// }

Rails 应用程序未在 StumbleUpon 上加载?将其添加到您的 ApplicationController

  before_action :allow_iframe_requests

private

  def allow_iframe_requests
    response.headers.delete('X-Frame-Options')
  end

https://github.com/rails/rails/issues/6311