Jump to content

Changing iframe src causes bac button to break


rain13

Recommended Posts

Hi.I am trying to load preview of link on iframe, but it breaks back and forward buttons.

function preview(elem){    alert( elem.href);    $('#float').attr('src', elem.href.replace("view","view2"));    $( "#float" ).show();    window.history.replaceState({}, "", elem.href);}

this function is called when user mouse hovers link. elem is the link obj. and elem.href is url that link user hovered points to. So basically I am making preview that should show url that link points to in iframe. Problem is it breaks back buttons - instead of going back it shows previous content in ifreame (it shows last preview that iframe showed, not loading previous page outside iframe). How to fix that?

Edited by SoItBegins
Link to comment
Share on other sites

Because this replaces current url so that user can copy it. Removing itdidn't change anything.Googling shows that it's well known problem - navigating inside iframe causes back button to navigate in iframe, not in page that contains ifram. Any fix?

Edited by SoItBegins
Link to comment
Share on other sites

It replaces the current URL in the history stack, so if you do that on several pages then the history (what happens when they press the back button) contains all of the URLs that you've replaced with instead of the actual pages they were on. The window.history object is specifically for controlling the behavior of the back and forward buttons.

Link to comment
Share on other sites

Edit: found fix for that:

$('#myIframe').get(0).contentWindow.location.replace('http://...');Source:http://stackoverflow.com/questions/786348/iframe-back-button-problem-dont-want-back-button-to-affect-iframe
Edited by SoItBegins
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...