I am making a simple online application.
I have a navigation bar with a few buttons and one “div” into which all the new contents will be loaded dynamically i.e. when I click “About”, it will load the page parts into the “div” without reloading the whole page with .load() function. The problem is:
what if I need to give a link to the Documents section of my web site, or the user wants to store this kind of link, the url is not rewritten when browsing my site. when the user stores the default link it will always link him to the default “Home” part.
How can I rewrite the URL and what is the most correct way to do this?
As option you can use
location.hash.E.g. user clicks
<a href="#about">About</a>and you’re loading the content of your “About” page.
Also the URL in browser’s address bar will be changed to something like
http://mysite.com/hello.jsp#about.So now user can copy this URL and visit it.
Then in
$(document).ready()you can check thelocation.hash, find that'#about'anchor in it and then load an appropriate content.Another option is to use Backbone.js or any other JavaScript MVC framework that you like which will help you to build rich client-side application and will handle such things for you.