SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Pressing F5

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Pressing F5

    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.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Martin.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by martbean View Post
    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.

    yes i am loading via ajax,so maybe this is the reason why it goes back to my index ?

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Martin.

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    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.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi @ScallioXTX @martbean, I change my mind instead of loading page via ajax i just load it through php like this...

    Thank you.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    http://net.tutsplus.com/tutorials/ot...te-for-apache/
    http://wettone.com/code/clean-urls
    Martin.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •