Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    targeting named anchor and the back button.

    Hey everyone, my first post here, and I need some help.

    I have 3 links that target to named anchors placed randomly on my single page.

    When I click on "myurl.com#target1" for for example, it takes me to the anchor named "target1", which is great, I continue browsing the page and eventually click on a link that takes me to another page.

    Now the problem occurs when I click the browser's back button, it takes me back to the "target1" anchor instead of the last position I was on the page.

    How can I make sure that it takes me back to the last position of the page instead of going back to the last anchor I targeted to.

    This site is viewed through a CD btw.

    Thanks for any help.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    What browser are you using? Because I just tested this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Example</title>
    </head>
    <body>
    
    <a href="#one">one</a> <a href="#two">two</a> <a href="#three">three</a> <a href="http://www.google.com">outside link</a>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="one">section one</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="two">section two</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="three">section three</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    
    </body>
    </html>
    and in both IE7 and FF, it doesn't follow the behavior you mentioned. It does in fact go back to your previous position and not the id.

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the response.

    Ok, I fooled around with what you tested with and It looks like it works fine for me as well, but I was able to reproduce my problem with a change, and this is my problem, I am opening a pdf document with my link. Try linking the external link to a pdf document in the same folder as the html and you will see the effect......I think.

    Thanks for the help so far, at least I am one step closer.

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Feels a tad hackish, but it works:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Example</title>
    <script type="text/javascript">
    <!--
    function onPageLoad()
    	{
    	window.location = "#top_of_page";
    	}
    
    window.onload = onPageLoad;
    // -->
    </script>
    </head>
    <body id="top_of_page">
    
    <a href="#one">one</a> <a href="#two">two</a> <a href="#three">three</a> <a href="test.pdf">outside link</a>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="one">section one</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="two">section two</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <div id="three">section three</div>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    
    </body>
    </html>

  • #5
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    although that does work, I need to it to go to last position....is there a way to further develop a hacked script to do that?

  • #6
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Ah yes, sorry I had forgotten that... Still thinking. I tried a combo php/javascript redirect, which works, but it takes a quick double back button click, which is horriby user-unfriendly.

    I'm leaving for a 2 hour drive home from work in 20 min, I'll brainstorm in the car.

    EDIT: You could use cookies or session variables to store the user's last position and then send them there on the page load. I feel like there must be a simpler way, but if that's not over the top hackish for you I could set up the script when I get home.

  • #7
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That sounds like an idea.

    I'm a newb, but I made this with some research, it isn't working yet. I'm sure I am making a mistake somewhere in here.

    <script type="text/javascript">
    <!--
    var scrollposition = document.body.scrollTop;
    function onMouseDown()
    {
    SetCookie("ScrollPos", scrollposition);
    }
    function onPageLoad()
    {
    document.body.scrollTop = ReadCookie("ScrollPos");
    }
    // -->
    </script>


  •  

    Posting Permissions

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