html5履歴オブジェクトを使用するのは初めてです。次のコードを試しました。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
history.pushState({somethinggoeshere:'but what?'}, 'Does a title go here?', '?begin=true');
window.addEventListener('popstate', function(event) {
console.log('popstate fired!');
console.log(event.state);
});
function dosomething()
{
document.getElementById('box').style.display = 'block';
document.getElementById('iframe').src = 't2.html';
history.pushState({somethinggoeshere:'but what?'}, 'Does a title go here?', '?complete=true');
}
</script>
</head>
<body>
<a onclick="dosomething();">Show box</a>
<div id="box" style="background:red; height:100px; display:none;"></div>
<iframe id="iframe" src="t1.html"></iframe>
</body>
</html>
[表示]ボックスを押すと、下に赤いボックスが表示され、iframeの内容がt1.htmlからt2.htmlになります。Chromeブラウザで戻るボタンを押すと、iframeの内容はt1.htmlに戻りますが、赤いボックスは消えません。
戻るボタンがiframeのコンテンツを復元するのに、レッドボックスのcssスタイルは復元しないのはなぜですか(display:noneに戻る)。