Question about iframes / bookmarkablity and back button functions.
This problem that I ran into is creating an iframe with an url without losing the functionality of the back button. Suppose all pages are in the same domain and the child pages inform the parent about loading the child page to update window.location.hash to change the current address bar of the browser.
Updating url works fine on IE / FF / webkit. But the back button works as expected in IE-8, but the browser back button does not work in FF / webkit (only the URL changes the previous page is not loaded). If we do not update the window.location.hash property, the return button works, but the window URL does not make sense.
Is there a way to get this functionality compared to browsers, or is there an easier way to do this (any other js libs). All pages are served from the same server to circumvent the resolution problem.
The following files:
- index_parent.html (contains frames)
- son.html
- grandson.html
the son and grandson are connected, and any navigation between the son and grandson in the parent iframe updates the address bar, but interrupts the back button in FF.
cat index_parent.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Parent</title>
<style>
body{
margin:0;
overflow: hidden;
}
iframe {
border: 1;
height: 100%;
width: 100%;
overflow-x: hidden;
}
</style>
<script language="javascript">
function update(url,title){
alert("parent_update")
document.title=title;
window.location.hash ="#" + url;
}
function parent_loader(){
alert("parent_loader")
if (window.location.hash.substr(1)) {
document.getElementById("embedframe").src=window.location.hash.substr(1);
} else {
document.getElementById("embedframe").src="son.html";
}
}
</script>
</head>
<body onLoad="parent_loader()" >
<H1> Parent</H1>
<iframe name="embedframe" id="embedframe" src="" frameborder="1" ></iframe>
</body>
</html>
cat son.html
<html>
<title> son </title>
<script language="JavaScript">
function son_loader() {
alert("son_loader");
if (self.location.href!=top.location.href) {
parent.update(location.href, document.title);
}
};
</script>
<body onload="son_loader()" >
<H1> son </H1>
<a href="grandson.html">Grandson < /a>
</body>
</html>
cat grandson.html
<html>
<title> grandson </title>
<script language="JavaScript">
function grandson_loader() {
alert("grandson_loader");
if (self.location.href!=top.location.href) {
parent.update(location.href, document.title);
}
}
</script>
<body onload="grandson_loader()" >
<H1> Grandson </H1>
<a href="son.html">Father </a>
</body>
</html>
source
share