javascript - 在 IE 8 中有时无法访问对象
问题描述
我有一个带有两个子框架的框架集。
<frameset rows="241px,*" id="header_fr">
<frame src="frame1.htm"/>
<frame src="frame2.htm"/>
</frameset>
我frame1.htm
只用作标题,每次更改内容时都会动态更改其大小frame2.htm
。
我改变frame1.htm
使用的大小parent.document.getElementsByTagName("frameset")[0].rows = new_size + ",*";
一切正常,但有时parent.document.getElementsByTagName("frameset")[0]
不再可用,它为 null 或不是 object。这个问题的原因是什么?
解决方案
你如何使用 JavaScript 函数?可能是 DOM 没有完全加载导致问题。您应该确保在对象完全加载后执行该函数。
我使用下面的代码进行测试,它在 IE 8 中运行良好,你可以检查一下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<frameset rows="241px,*" id="header_fr">
<frame src="frame1.htm" />
<frame src="frame2.htm" />
</frameset>
</html>
框架1.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body style="background-color:aquamarine">
111
</body>
</html>
框架2.htm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body style="background-color:burlywood">
222
<script>
parent.document.getElementsByTagName("frameset")[0].rows = 40 + ",*";
</script>
</body>
</html>
推荐阅读
- google-bigquery - 无论如何将现有数据/历史从firestore加载到bigquery?
- python - 如何从这个输出中减去或找到差异?
- cybersource - 我可以使用我的测试环境商家 ID 和密钥来测试 flex 缩微帖子吗?
- sql - 如何在 Hive Sql 中模拟循环?
- google-photos - iOS 版 Google 相册在哪里隐藏“助手”标签?
- opencart - 关于 Opencart robots.txt 的建议
- ffmpeg - ffmpeg - .m4a 输出的默认格式是什么?
- java - 按其内部另一个 LinkedHasmap 的值以降序对 LinkedHashMap 进行排序
- c# - 查找集合是否比 C# 中的元组列表更快、更优化?
- php - PHP 内存访问