rain13 Posted May 6, 2014 Share Posted May 6, 2014 (edited) 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 May 6, 2014 by SoItBegins Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2014 Share Posted May 6, 2014 Why are you changing the history state? Do you think that might have something to do with it? Do you know what that line is doing? Link to comment Share on other sites More sharing options...
rain13 Posted May 6, 2014 Author Share Posted May 6, 2014 (edited) 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 May 6, 2014 by SoItBegins Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2014 Share Posted May 6, 2014 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 More sharing options...
rain13 Posted May 7, 2014 Author Share Posted May 7, 2014 (edited) 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 May 7, 2014 by SoItBegins Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now