jemz — 2013-07-04T01:58:26-04:00 — #1
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.
Thank you in advance.
martbean — 2013-07-04T10:38:13-04:00 — #2
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.
jemz — 2013-07-04T11:06:41-04:00 — #3
yes i am loading via ajax,so maybe this is the reason why it goes back to my index ?
martbean — 2013-07-04T11:12:58-04:00 — #4
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.
scallioxtx — 2013-07-04T14:39:37-04:00 — #5
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.
jemz — 2013-07-05T04:52:42-04:00 — #6
Hi @ScallioXTX @martbean, I change my mind instead of loading page via ajax i just load it through php like this...
martbean — 2013-07-05T05:49:25-04:00 — #7
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: