我有一個包含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