...

View Full Version : history.back() in iframe



johnsmith153
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 ) {
history.back();
} else {
window.history.back();
}
}


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.

felgall
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum