javascript - 框架集和 javascript 变量交互
问题描述
我知道框架集并不完全是尖端技术,但我不得不调试一个旧应用程序并且遇到了一个意想不到的行为。
这里有一些简单的 HTML 页面来展示这种行为。
索引.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>
菜单.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>
内容1.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>
内容2.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>
行为是预期的:当我们单击菜单链接时,子菜单的内容会更新。
现在,我在 content2.html 的正文中添加一行:<script>var name = "why" ;</script>
如果我点击“内容 2”链接,内容会刷新,但从现在开始,当我点击任何链接时,框架的内容会在新选项卡中打开。我可以使用任何现代浏览器(Chrome、Firefox、Edge 等)重现此行为:name
“主”脚本中的 javascript 变量会更改框架集的行为。
有人对此有解释吗?我不认为这name
是一个保留关键字?为什么这个新标签打开而不是一个损坏的脚本?
解决方案
var name
,如果用作全局变量,则与 相同window.name
。
window.name
是保存框架名称的属性。
如果您将名称更改为不匹配的名称target
(例如 from submenu
to why
),则没有匹配的目标,因此必须创建一个新目标。
推荐阅读
- typescript - const enum HttpStatusCode 如何工作?
- xpath - 使用 Xpath 1.0 提取最后一个单词
- vim - 在 Vim 中动态替换(或附加/前置)选择
- c# - 矩形填充在 printvisual 中不透明
- typescript - 在编译时检查变量是否有类型?
- c# - 在 web api 端点中将 url 路径作为参数传递
- c# - 基于模型 ASP.NET Core MVC 5 中的另一个属性分配属性的值
- javascript - React i18n,如何插入字符串(即不使用
零件)? - python - 从配置文件模型中获取用户实例
- javascript - 如何组合每个选择标签的数据