SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    History.go(-1) And Anchors...

    I use

    PHP Code:
    ... javascript:history.go(-1); ... 
    A lot on BUTTONs etc for page navigation but recently I had to include anchors on some pages and now I get a complaint back saying the 'Go Back' buttons don't work.

    This is basically down to the anchors on the page as they are included in IEs history. Does anyone have any idea's if this has been fixed via some javascript maybe ?

    All the pages are created dynamically btw. Any help or ideas are welcome, as always.


  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're saying the back doesn't work when the previous page points to a named anchor? Such as www.domain.com/page.htm#anchor ???
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are they created dynamically WITH? PHP? Perl?

    If you are using PHP or Perl, couldn't you get the value of history.go(-1) and regex the anchor off of the end, and then save that value to a variable, and then echo the *variable* as your 'Go Back' button?

    No more anchors, at least? Depends on what you're using. If you are using Javascript to generate the pages dynamically, then i'm not sure if Javascript even has Regex, but I'm sure you could still do something like a character match and acheive the same effect.
    Ryan

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gybbyl - the history object in JS doesn't store URLs - just a length.

    You could, however, use PHP or Javascript to link the user to the referring page
    PHP Code:
    $link '<a href="' $_SERVER['HTTP_REFERER'] . '">Back</a>'
    or
    Code:
    <button onclick="location.href = document.referrer">Go Back</button>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Simple... If you want to use javascript, add code to those named anchor links that keeps them out of the history.

    In Netscape browsers this would be:
    Code:
    onclick="location.replace(history.previous);"
    The code would be a little more complicated for cross browser use but with a little PHP added to the mix it could be:

    Code:
    onlick="location.replace('<?php echo $_SERVER['HTTP_REFERER'] ?>');"
    Just to give another option.
    Wayne Luke
    ------------


  6. #6
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    Gybbyl - the history object in JS doesn't store URLs - just a length.
    Oh, right *cough*.

    I was just seeing if you guys were awake. ;]
    Ryan

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    The referer is unreliable though, especially through firewalls and some antivirus programs. It's better than relying solely on the history object, but don't expect it to work 100% of the time.

    Here's my proposed solution:
    PHP Code:
    <a href="<?php echo $_SERVER['HTTP_REFERER'];?>" onclick="history.go(-1); return false;">&laquo; Back</a>

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like, much thanks people; your contributions really have helped a lot... The referrer shouldn't be a problem as it's a closed Intranet But something to look at if it were for the Internet as well so much thanks...


Bookmarks

Posting Permissions

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