Question

i've made some basic pages with the hashchange event plugin. but now i want to build something bigger but cant find the right way to do it in an easy way.

the index.html starts with an animated loginbox. if you log into your account, the loginbox fades away - the hash changes to #start; content+header/footer loads and fades in. this part is no problem for now.

the main reason is to activate the browser back button without leaving the index.html. i use ajax and hashes to archive this. #start loads the main-interface after logging in. #messages loads the messages-interface. both have some extra scripts+animation that have to get triggered everytime the hash changes.

my problem in general is, that i dont know how to get to the sublinks. for instance: the user is in #messages (ajax loads /php/messages.php, fades it in). the messages-interface shows his inbox with a link at the bottom to get to his outbox. what options are there for the link? the messages.php waits for a GET request like ?s=n for new message, ?s=o for outbox. how can i get this done with in mind: active the browser back button?

is there a way like changing the hash to #messages/outbox + loading the file /php/messages.php?s=o ? how should the jquery code look like? for the main navigation i used a switch-function, like 'switch(hash) {case #start; case #messages}'; this cant be the best solution, as i'll get a lot of more links/hashes.

any suggestions/solutions?

Was it helpful?

Solution

I guess you will always have to look up for the url if you want your urls to be useful for the user more than just giving back button functionality.
Consider users pasting a previously saved url while your page is open, you want to get them to the place they're looking for, right?
So, having this in mind, I would only care about changing the hash (when you want to mantain it to a history / bookmarkable state) and then, handle pages and actions stuff on hashchange event. If you are using hashchange event plugin, you probably want to take a look at jQuery BBQ: Back Button & Query Library, which "provides a full .deparam() method, along with both hash state management, and fragment / query string parse and merge utility methods." making it much more easy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top