框架集和 javascript 变量交互

Frameset and javascript variables interaction

我知道框架集并不是最先进的技术,但我不得不调试一个旧的应用程序,我遇到了一个意想不到的行为。

这里有一些简单的 HTML 页面来展示这种行为。

index.html :

<html>
  <frameset rows="22,*" border="0">
    <frame name="menu" src="menu.html" marginheight=0 marginwidth=0>
    <frame name="submenu" src="content1.html">
  </frameset>
</html>

menu.html :

<html>
  <body>
    <table width=100% border=0 spacing=1>
      <tr>
        <td><a href="content1.html" target="submenu">Content 1</a></td>
        <td><a href="content2.html" target="submenu">Content 2</a></td>
      </tr>
    </table>
  </body>
</html>

content1.html :

<html>
  <body>
    <p>Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.</p>
  </body>
</html>

content2.html :

<html>
  <body>
    <p>Seasonal, whipped java aftertaste lungo ristretto, a turkish chicory affogato saucer. Medium, spoon et skinny americano cappuccino lungo dripper.</p>
  </body>
</html>

行为符合预期:当我们单击菜单 link 时,子菜单的内容会更新。

现在,我在 content2.html 的正文中添加一行:<script>var name = "why" ;</script>

如果我点击 "content 2" link,内容会刷新,但是从现在开始,当我点击任何 link 时,框架的内容 在新标签页中打开。 我可以使用任何现代浏览器(Chrome、Firefox、Edge 等)重现此行为:"main" 脚本中的 name javascript 变量改变了框架集。

有人对此有解释吗?我不认为 name 是保留关键字?为什么打开这个新标签页而不是损坏的脚本?

var name,如果用作全局,与window.name.

相同

window.name 是保存框架名称的 属性。

如果您将名称更改为与 target 不匹配的名称(例如从 submenu 更改为 why),则没有匹配的目标,因此需要一个新的目标待创建。