I'm developing a simple one page website, where the pages scroll horizontally using the scrollTo() javascript library. I have a home / about / contact page. I was wondering if there was a way to still use some form of URL routing like www.example.com/about, to get the about page, and would get updated in the browser when the page was clicked in the navigation.
Asked
Active
Viewed 206 times
0
-
sounds like you don't have a one page website, if you have home/about/contact...can you clarify? – hvgotcodes Nov 13 '12 at 15:48
-
Take a look at how jquery mobile drives its hashing model: http://jquerymobile.com/demos/1.0a4.1/docs/pages/docs-navmodel.html – Lowkase Nov 13 '12 at 15:50
-
Something like this? http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page – MassivePenguin Nov 13 '12 at 15:50
2 Answers
2
Your easiest bet is going to be to use hashes. i.e. www.example.com/#about
You can then use window.history
(more reading) in order to change the URL without a page reload. Specifically, you will be looking for history.pushState() or history.replaceState()
Depending on what browser support you need, you might need something like History.js to fall back in IE.

Chris Sobolewski
- 12,819
- 12
- 63
- 96