【问题标题】:unable to access child iframe DOM from parent webpage无法从父网页访问子 iframe DOM
【发布时间】:2014-03-08 14:17:23
【问题描述】:

我被分配了在 iframe 中打开网页的任务,用户可以导航到 iframe 中的内页。但我的任务是使用 Javascript 或 Jquery 获取 iframe 内页的 URL。

让我清楚地解释这个问题, 我有一个网页(比如 abc.corp.com),并且正在使用 iframe 显示另一个网页(比如 bcd.corp.com)。基本上两者都来自“corp.com”,但我无法访问子 iframe DOM,我们在尝试访问 iframe 对象时获得权限被拒绝访问。

子 iframe 页面 (bcd.corp.com) 由其他团队开发和维护,我们无权访问该网页。

我们尝试将父页面和子 iframe 页面的 document.domain 属性更改为同一域“corp.com”,但我们无法修改子 iframe 页面域。

请提供解决此问题的方法。

提前致谢

【问题讨论】:

标签: javascript jquery dom iframe cross-domain


【解决方案1】:

“无法从父网页访问子 iframe DOM”

我认为这是 iframe 的一个目标,即分离 DOM。但是,您可以通过类似的方式获得访问权限。

function getIFrameDom( referenceToYourIFrame ) {
     return frameRef.contentWindow ? frameRef.contentWindow.document :  frameRef.contentDocument
}

【讨论】:

  • 感谢您的回复。尝试了 contentWindow 和 contectDocument。无法访问它。还有其他建议吗??
猜你喜欢
  • 2011-07-08
  • 1970-01-01
  • 2013-10-28
  • 1970-01-01
  • 1970-01-01
  • 2011-02-06
  • 2010-11-20
  • 2016-03-21
相关资源
最近更新 更多