I have 2 simple html pages: parent and child. Parent stores child inside the iframe
.
Parent.html:
<html>
<head></head>
<body>
<input type="text" id="text" />
<input type="button" value="change hash" onclick="javascript:changeHash()" />
<iframe src="Child.html"></iframe>
<script type="text/javascript">
function changeHash () {
window.location.hash = document.getElementById('text').value;
}
</script>
</body>
</html>
And Child.html:
<html>
<head></head>
<body>
<input type="button" value="go back" onclick="javascript:goBack()" />
<script type="text/javascript">
function goBack () {
this.history.back();
}
</script>
</body>
</html>
I use change hash button to add several hashes to history. And when I press go back button inside the iframe
- the hash of the Parent page is changed. And seems that this is behavior by the spec.
So the question is: is it possible to prevent propagation of going back from the iframe to it's parent page? So I would like the iframe not to change the parent's history/hash.
Note: the same behavior is for go
function (actually, go(-1)
is the same as back()
).