【问题标题】:frame inside of iframe in IEIE中iframe内部的框架
【发布时间】:2012-04-13 19:28:48
【问题描述】:

我有这个环境:

Page1.html:

<iframe id="ifr" name="nifr" src="Page2.html" enableviewstate="true" width="800" height="600" frameborder="1" style="z-index:0" ><p>Su navegador no soporta iframes.</p></iframe>

Page2.html:

<frameset rows="30,*" frameborder="no" framespacing="0">
    <frame id="titleFrame" frameborder="no" marginwidth="0" marginheight="0" scrolling="no" src="title.html">
    <frame id="viewerFrame" frameborder="no" marginwidth="0" marginheight="0" scrolling="no" src="anotherPage.html">
</frameset>

如何使用 javascript 获取框架“viewerFrame”?我只在 Internet Explorer 上工作

提前致谢

【问题讨论】:

  • 您正在使用框架、iframe 和 IE。听起来像是撒旦的仪式。
  • 从什么级别获取 iframe?
  • @OhCaN 我知道,也无能为力,“Page2.html”不是我的网页,我要创造奇迹:S
  • @epascarello 获取 Page2.html 的 frame,Page2.html 作为 iframe 在 Page1.html 内部。有点棘手

标签: javascript html iframe frame


【解决方案1】:

首先,您将为框架元素添加一个name-属性。

<frameset rows="30,*" frameborder="no" framespacing="0">
<frame name="titleFrame" id="titleFrame" frameborder="no" marginwidth="0" marginheight="0" scrolling="no" src="title.html">
<frame name="viewerFrame" id="viewerFrame" frameborder="no" marginwidth="0" marginheight="0" scrolling="no" src="anotherPage.html">
</frameset>

那你可以从Page1.html试试这个:

var viewerFrame=document.getElementById('ifr').contentWindow.viewerFrame;

【讨论】:

  • 嗯...您可以在问题中提到这一点:“Page2.html 不是我的网页”。你真的需要一个奇迹......这意味着,如果你没有编辑 Page2.html 的权限,你就无法获得对框架集的任何访问权限。
  • 我试过你的 sn-p 代码,但我得到“未定义” D:编辑:我明白了,特别是在第 2 页我只有一个框架时,谢谢你的帮助
  • @NatyBizz 是的,这是意料之中的,在您对 OhCaN 发表评论之后。就像我在对自己的回答的评论中所说的那样,如果您无法编辑第三方网站,则无法访问它。
【解决方案2】:

如果我理解您想要正确执行的操作,您可能正在搜索类似的内容:

$("#ifr").contentWindow.$("#viewerFrame").html();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-14
    • 2010-12-10
    • 2016-08-05
    • 2012-11-20
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    相关资源
    最近更新 更多