【问题标题】:Javascript permission denied - different portJavascript 权限被拒绝 - 不同的端口
【发布时间】:2011-01-26 21:29:04
【问题描述】:

我有一个在端口 3000 上运行的 rails 应用程序。有问题的页面有一个 iframe,我需要根据 iframe 中加载的内容的高度调整它的大小。

<iframe id="ifrm_col3" name="ifrm_col3" frameborder="0" 
src="<%=invite_path(@invite.alias)%>" 
onload="util.resize_iframe('ifrm_col3');"></iframe>

调整大小功能在这里:

util.resize_iframe = function(frame_id) {
  var h = document.getElementById(frame_id).contentWindow.document.body.scrollHeight;
  document.getElementById(frame_id).height = h; 
}

加载 iframe 后,我在 FireBug 中看到此错误:

Error: Permission denied for <http://192.168.0.157> to get property Window.document from <http://192.168.0.157:3000>.
Source File: http://192.168.0.157:3000/javascripts/application.js?1268327481
Line: 84

为 iframe 渲染的 HTML 如下所示:

<iframe id="ifrm_col3" name="ifrm_col3" frameborder="0" 
            src="/invite/my-invite-1" 
            onload="util.resize_iframe('ifrm_col3');"></iframe>

iframe 的 src 是相对路径,但不知道为什么不保留父页面的端口信息。这个问题有什么解决方法吗?

我尝试在父页面中创建一个函数并从 iframe 调用它,但遇到了同样的问题。

由于站点中的额外功能,我需要为 rails 应用程序使用端口 3000。

感谢任何建议。

【问题讨论】:

    标签: javascript iframe permissions


    【解决方案1】:

    您确定&lt;%=invite_path(@invite.alias)%&gt; 实际上会输出相对路径吗?一路上什么都没有(错误地)解决它? src 属性的实际输出最终是什么样的?

    【讨论】:

    • @T.J.克劳德,谢谢你的回复。是的,我用 HTML sn-p 更新了帖子。
    • @Grnbeagle:如果 iframe 所在的页面是通过端口 3000 提供的,我看不出浏览器应该(错误)将其解释为端口 80 而不是 3000 的任何原因。
    • @T.J.克劳德,你是对的。这不应该发生。是我的错。问题中的页面使用需要设置 document.domain 的 stomp 客户端库。我正在研究如何绕过它。不过感谢您的意见。
    • @Gmbeagle: document.domain -- 我怎么没想到呢?!祝你好运。
    猜你喜欢
    • 1970-01-01
    • 2015-07-02
    • 2014-12-29
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 2021-12-31
    • 2016-09-24
    • 2015-08-30
    相关资源
    最近更新 更多