View Full Version : history.back() in iframe

12-03-2012, 04:35 AM
I'm having a nightmare trying to code a simple back button in an iframe. A Fancybox iframe to be exact. Imagine a site which can open up links in a Fancybox iframe as a preview. The user could open a link and keep clicking inside the iframe. I want them to also be able to click Back inside the iframe.

Also, I don't want to use an onclick handler, I just want a solution something like this:

function go_back() {
if( this_is_an_iframe === true ) {
} else {

If I use window.history.back() for everything then it works ok on some browsers, but not on others. Some browsers (including mobiles) will just go back the entire page (not the iframe). I'm sure there's a solution to serve slightly different code when in an iframe.

12-03-2012, 07:13 AM
Going back relies on the way the browser uses the history list. It isn't going to make any difference where or how you call back it will go back one entry in the list that the browser has saved.

You can control whether new pages/frames get added to the list or overwrite the prior entry but that's about as much control as you get.