history.back() in iframe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    history.back() in iframe

    I have an iframe in which there is a link with href="javascrip t:history.back()"

    But instead of moving the iframe's location back, it moves back the main page.

    Any solution?
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Solved:

    For an iframe, back link should be:[html]<a href = "javascript:par ent.document.ge tElementById('i d_Of_Iframe').c ontentWindow.hi story.back();" >Back</a>[/html]

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      EDIT- solved while posting.

      i cannot reproduce the problem in FF or ie7, is this an issue on either of those?

      ---------
      general suggestions:
      name your iframe and set the A's target attrib to the name.
      try this.history.ba ck()
      use javascript:void (back()) in firefox, or something like window.back?bac k():history.bac k()

      keep you own page history stack using push() and pop() to change location of frame.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by rnd me
        i cannot reproduce the problem in FF or ie7, is this an issue on either of those?
        With Firefox.
        Originally posted by rnd me
        ---------
        general suggestions:
        name your iframe and set the A's target attrib to the name.
        This works good! I missed using target. I had in mind that target is by default the same frame in which the <a> is. Which is actually right, but somehow, history.back() is an exception.
        Originally posted by rnd me
        try this.history.ba ck()
        use javascript:void (back()) in firefox, or something like window.back?bac k():history.bac k()

        keep you own page history stack using push() and pop() to change location of frame.
        That is only good if you have to show a drop down when a user click on a custom back button inside the page. You can thus ask him to choose any of the previous pages. That can be used.

        Thanks

        Harpreet

        Comment

        • hxie
          New Member
          • Jun 2012
          • 1

          #5
          try this:
          //click todo
          if(document.ref errer){
          window.location .href = document.referr er
          }

          Comment

          • tazosmr
            New Member
            • Feb 2012
            • 4

            #6
            Originally posted by hxie
            try this:
            //click todo
            if(document.ref errer){
            window.location .href = document.referr er
            }


            thanks so much!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!

            I used this one too:

            Code:
            <script type="text/javascript">
            alert(parent.location.href);
            alert(document.referrer);
            if (parent.location.href != document.referrer )
            {
              document.write('<a style="float:left;background-color:red;" href="javascript:self.history.back(-1);">Go Back</a>');
            }
            </script>

            Comment

            Working...