Iframe history management and site bookmarkability

C

chanelzy

I have my main site content loaded into an iframe while a small flash
app is placed in the main page:

<html><body>
<iframe id="content" src="content.html" onload="updateTop();"></
iframe>
<div id="flash"><!-- embed code --></div>
</body></html>

Everything about this structure works fine except the url on the
address bar stays the same. When i try to change the hash of the
"top" window whenever a link is clicked, this causes two history
indexes to be created:
document.body.onclick = function(event) {
event = event || window.event;
var target = event.target || event.srcElement;
if (target.nodeType == 3) { target = target.parentNode; }
if(target.href && target.href!="#") {
top.location.hash = target.href; // change hash of parent
}
// allow page to be loaded
}

I then used the location.replace hack to change the top window hash
and prevent an extra history index from being created:
document.body.onclick = function(event) {
event = event || window.event;
var target = event.target || event.srcElement;
if (target.nodeType == 3) { target = target.parentNode; }
if(target.href && target.href!="#") {
top.location.hash = target.href; // change hash of parent
top.location.replace(target.href);
}
return false; // prevent extra history index
}

This allowed the top window to be bookmarkable and utilize the history
back/forward functions, but it doesn't actually contain the iframe's
history index so the actual contents of the page does not change.

I want the flash to stay put so users can utilize it uninterrupted
from page reloads. If anyone knows how to make an iframe as the main
content container while also making the parent window barkmarkable, I
would really love to know how.
 
J

Joost Diepenmaat

chanelzy said:
If anyone knows how to make an iframe as the main content container
while also making the parent window barkmarkable, I would really love
to know how.

While it's sort of possible, I really don't recommend it. IE, Firefox
Opera and Safari all have subtlely different ideas of what is considered
a history event, what happens when you use the back and forth buttons
and when/if a change in the #hash is detectable or not.

Bookmarkability alone is fairly straightforward, but you may lose
intuitive back- and forward-button functionality unless you're prepared
to do a lot of work (or find some library that does it for you).

Unless you're building a single-page application, I'd recommend ditching
the frames altogether.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top