【问题标题】:How to access sibling frames in HTML?如何访问 HTML 中的同级框架?
【发布时间】:2022-10-14 15:21:55
【问题描述】:

我有以下 HTML 文件: 1:索引.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>This is a frameset with OBJECT in the HEAD</TITLE>

</HEAD>
<FRAMESET>
  <FRAME src="second.html" id="second" name="second">
    <FRAME src="bianca.html" id="bianca" name="bianca">
   
</FRAMESET>
</HTML>

2:bianca.html

<!-- In bianca.html -->
<html>
  <head>
    <title>Bianca's page</title>
  </head>
  <body>
    ...the beginning of the document...
    <p id="test">
      <script type="text/javascript">
        console.log(window.parent.second);
      </script>
      ...the rest of the document...
    </p>
  </body>
</html>

3:第二个.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1 id="test1"></h1>
  </body>
</html>

但是,我无法访问同级框架(名为第二个),因为脚本在控制台中记录未定义。如何访问同级框架?

【问题讨论】:

    标签: html frames


    【解决方案1】:

    框架元素是window.frames 的属性,而不是window 的属性。

    window.parent.frames.second
    

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      相关资源
      最近更新 更多