我有一个包含iframe的页面,我只想跟踪iframe的历史记录。 我试图用这样的历史对象:只跟踪iframe历史
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function checkFrameHistory() {
alert(window.frames["test2"].history.length);
}
function checkThisHistory() {
alert(history.length);
}
</script>
</head>
<body>
<iframe name="test2" src="test2.html"></iframe>
<div>
<input type="button" onclick="checkFrameHistory()" value="Frame history"/>
<input type="button" onclick="checkThisHistory()" value="This history"/>
</div>
</body>
</html>
test2.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function checkMyHistory() {
alert(history.length);
}
</script>
</head>
<body>
<div>
Test2
</div>
<div>
<input type="button" onclick="checkMyHistory()" value="My history"/>
</div>
</body>
</html>
但它实际上给我的历史,包括父窗口。
例如,我去了主窗口中的另一个站点,并返回到我的iframe测试站点。 window.frames["test2"].history.length
和history.length
仍然给我通过增加长度相同的计数2.
我做错了吗?有没有办法只跟踪iframe的历史?
中有什么test2.html页? – thisgeek
刚刚添加了test2.html,但它只是一个简单的测试页面。谢谢! – evanwong
此[INFO](http://khaidoan.wikidot.com/iframe-and-browser-history)可以提供更多信息。 – arttronics