views:

25

answers:

1

Hi, I have a page that contains an IFRAME with src to page 1 I then created a button on the parent page that switches the IFRAME source to page 2. On Chrome when I hit the back button it directs me to the history page of the parent page instead of just redirecting the IFRAME content back to page 1.

Has anyone seen this behavior? does it have any fix?

Thx

A: 

A simple solution I have used is to set the location.hash of the parent frame to be the URL (or other unique ID) of the child iframe.

When the user presses the back button location.hash will change.

Then the following observer will update your frame (need to be turned off when you change the URL)

var currentHash= window.location.hash, myiFrame = document.getElementById('myiFrame');
window.setInterval(function () {
         if (window.location.hash != currentHash){
             currentHash = window.location.hash;
             myiFrame.src = currentHash
         }
    },250);

Pullets Forever