Today we will show you how to read the part of URL following after the hash tag and process it to the specified function. Using hash tag links is a popular practice between AJAX calls based websites as hash tag URL extension can be easily changed without reloading the page.
Kartogram uses slightly ’reveresed ingeneering’ methods for such practice as each link, once clicked is updating hash tag URL part to mark the action that is being taken. Also it fires up the jQuery call assigned to that particular link hence avoiding repeated URL reading for hash tag part change.
Following function needs to be called on window load:
As you see we read the hash part of the URL and pass it to the function called ’processhash’:
As you see we used switch function to switch possible hash tag parts and fire up adequate functions. Those functions can be absolutely anything, from showing some hidden divs to AJAX calls to load some database based content.
For a quick example follow the link and check all the link bits explained above: http://www.kartogram.co.uk/#!what-we-do
If you read our previous post you already know how to avoid browser refresh once such link is followed from the external souce.
So get coding and as usual, should you need any further information feel more than welcome to use the comments section below or contact us directly at firstname.lastname@example.org .