Page 1 of 1
working with [advanced] URLs
Posted: Mon Jul 27, 2009 10:29 pm
by koguee
i can't find any resource online that discusses on how to evaluate urls (if that would be the term) such that i can make use of the # sign or the : sign. what i would like to happen is to know how to use the # like the ones on facebook. i think that's ajax thingy. the url on the address bar changes but only a part of the page is changed (i.e., albums, next image, previous image). In the same way, how to use the colon :
any insight or explanation would help a lot. thanks folks.
Re: working with [advanced] URLs
Posted: Tue Jul 28, 2009 3:15 pm
by tr0gd0rr
The part after the # is called the "hash" or "fragment". It is not sent to the server, but the browser can use it to scroll to a given place on the page.
For example, visiting mypage.php#article will scroll to <a name="article"></a> or <h2 id="article">Article Title</h2>.
In ajax applications, the fragment is often read by JavaScript (window.location.hash) to restore the application to some state. That way you can share a url with someone. Also, the fragment allows the browser back button to cause the application to revert to a previous state instead of backing out of the application.
Re: working with [advanced] URLs
Posted: Thu Jul 30, 2009 8:14 am
by koguee
Does that mean if I click on a link with the hash, i can parse the url and get exactly what proceeds the hash sign then I can make an AJAX call that has something to do with it (the word after the #). What if there are more than one hash in the link? Could that be possible?
Thanks for the reply. any links you can share so i can note on this further?
how about the colon (:). Does it work the same way the hash (#) works?
Thanks again.
Re: working with [advanced] URLs
Posted: Thu Jul 30, 2009 9:21 am
by jackpf
I believe the colon is for specifying a port to connect to.
Re: working with [advanced] URLs
Posted: Tue Aug 04, 2009 12:27 pm
by tr0gd0rr
koguee wrote:Does that mean if I click on a link with the hash, i can parse the url and get exactly what proceeds the hash sign then I can make an AJAX call that has something to do with it (the word after the #). What if there are more than one hash in the link? Could that be possible?
Thanks for the reply. any links you can share so i can note on this further?
how about the colon (:). Does it work the same way the hash (#) works?
Thanks again.
Yes, there are two parts to a hash system:
1) On an action such as clicking a link, intercept the action and do something dynamic such as an ajax call. At that time, you want to update "window.location.href = '#' + something" where the something is data that describes something about the current state of the application.
2) A function that runs after the window loads on the initial application startup. The function should read "window.location.hash" and restore the state of the application from that data.
For example, say you have an online email application. If the user clicks "reply" to a certain message, you might change the "window.location.href" to be '#replyto/1001'. If someone were to copy the full url (e.g.
http://myemailapp.com/#replyto/1001) and paste it into the browser later, you could read "window.location.hash" on application startup and immediately show the input screen for replying to the message with id 1001.
You won't need to use multiple "#" in the hash. I suppose you could; you should be able to use any data format that makes sense to the application. A common format is "#/param1/value1/param2/value2".
Re: working with [advanced] URLs
Posted: Tue Aug 04, 2009 4:56 pm
by josh
Look at collegehumor:
http://www.collegehumor.com/video:1918434
Here the video:whatever comes thru in the request_uri. This is SEO friendly.
Their old way was with the hash, when the videos changed the URL changed accordingly so you could copy & paste the URL to someone and it would take them to the currently playing video. This made me curious about SEO which I guess they realized later on and changed to this system where there is a div below the video with "share url" that updates, and the current URL does not.
The advantage of a hash: ajax actions without breaking the concept of UNIFORM resource locators
disadvantage: breaks uniform resource locators ( at least for clients that do not support the javascript to load up the content )
lol