Hi, I have problem in my page when i am going to press the F5 or i will refresh the page it will go back to my index.php but what i want is that after the page is refreshed it will still remains on the current page where the user is viewing…for example i have navigation bar “Home,journal,work,contact us”. Now if the user is in the contact us page then if the user will press the F5 or he will refresh the page in the browser,the contact us will still be loaded and it will not go back to the index.php or in my home…can you help me please how to achieve this.
Are you loading content via AJAX or something? When you’re on the contact page, what is the URL in the address bar? Reloading the page won’t change the URL so I’m not exactly sure what’s happening.
No “maybe” about it; that’s exactly what’s happening. There’s an HTML5 API called pushState() (demo) which does what you need but you’ll want to account for older browsers too. Google “ajax browser history” for a bunch of articles on the subject.
Have a look at history.js. Works fine with HTML5 browsers and has fallback for HTML4 browsers. Best script I’ve found for URL history manipulation so far.
ScallioXTX: funnily enough I was reading the latest .net magazine last night and there was a good article/tutorial about the History API and that also recommended history.js.
Jemz: If you’re going down that route I would suggest using mod_rewrite to have cleaner, simpler and more search engine-friendly URLs. There are many articles on the web but here’s a couple: