How to read the # end of a URL?

Discussion in 'Programming' started by zerxer, May 28, 2008.

  1. #1
    Alright so I don't really know how to word this which is why I couldn't just do some simple Google searches.

    Let me start with an example. When you go to your Gmail account and you append #spam to the end of the URL after it's already loaded and hit enter, it'll know to make the AJAX call to load the spam section. Even if you don't already have the Gmail page loaded and you go directly to "http://mail.google.com/mail/#spam", it knows to load the spam section first instead of the inbox.

    So my question is what is the best way to constantly watch the URL to see when they add something at the end with a #? How do you check it initially? I was really hoping I could see it in some PHP var like $_SERVER so I could append things to the end of the URL when making AJAX calls so people could then link people directly to that page and it'd know what to initially load for them but I couldn't see anything after the # symbol. I tried just making a blank PHP page that just did print_r($GLOBALS) and went to it like page.php#test as a test and it didn't have the #test.

    I assume you can only do this using some type of client-side scripting so if anyone knows of a good method, I'm all ears.

    Thanks.
     
    zerxer, May 28, 2008 IP
  2. Freud2002

    Freud2002 Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes it's actually done by client-side scripting, as the # part is not sent to the server in any way.

    I don't really know how to do this, I just know Google implemented it in GWT with the HistoryListener interface. You are then able to catch every change in the address bar.
     
    Freud2002, May 30, 2008 IP