Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    history.back() in iframe

    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.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 662 Times in 651 Posts
    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.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts