Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:56:50+00:00 2026-06-18T04:56:50+00:00

I have a website that loads its content by the user clicking a button,

  • 0

I have a website that loads its content by the user clicking a button, then the clicks calls a javascript function that updates just the content of a central <div> element by changing its inner html with AJAX and jQuery.

So for example, when the visitor wants to go to my contact page, they click the contact button, and the div’s content is updated to the contact form by pulling that content from an external file and using it to replace the div’s innerHTML. The actual address of the entire page doesnt change, as the entire page isnt being reloaded, just the innerHTML of the div.

Further to this, my site uses PHP, and I’ve coded it such that various content can be populated in the div on page load by passing variables in the url. For example, index.php?page=home will tell the PHP script to load the home page content from an external file, while index.php?page=contact will load the contact form. This way search engines can find each page and their content by following these links in my sitemap.

My problem is that if a visitor clicks a button and loads different content into the div, then clicks the reload button of their browser or presses CTRL+R, the entire page reloads and the div of course reverts to its original content.

My question is, is there a way to load a particular page when the browser refreshes? For example, if the visitor has loaded the page index.php?page=home then clicked on the contact button and updated the div content, then pressed the refresh button of their browser, can i somehow write a script that will load index.php?page=contact instead, preserving the look of the page and the content?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:56:51+00:00Added an answer on June 18, 2026 at 4:56 am

    Option 1: location.hash

    Easier, but not as robust. Worth taking a look at, but if you want to store the states of multiple elements, you probably want option 2.

    Here’s a demonstration of the code below.

    Example:

    function onHashChange() {
        var hash = window.location.hash;
        // Load the appropriate content based on the hash.
    }
    
    $(window).on('hashchange', onHashChange);
    $(document).on('load', onHashChange);
    
    $('#button').click(function(){
        window.location.hash = "home";
    });
    

    This way, all you need to do is change the hash on button change and handle the page load using the hashchange event.


    Option 2: History API using History.js

    A little harder to implement (but not much!), but infinitely more robust. Relies on a widely used framework.

    Another, and perhaps a cleaner way of doing this would be to use the History API. It allows you to change window.location without refreshing the page, allowing you to handle those changes using JavaScript.

    Not all browsers support the API yet though, but you could use History.js, which provides location.hash fallbacks if needed. Here’s a demo.

    From History.js’s github page:

    History.js gracefully supports the HTML5 History/State APIs
    (pushState, replaceState, onPopState) in all browsers
    . Including
    continued support for data, titles, replaceState. Supports jQuery,
    MooTools and Prototype. For HTML5 browsers this means that you can
    modify the URL directly, without needing to use hashes anymore. For
    HTML4 browsers it will revert back to using the old onhashchange
    functionality.

    Example of History.js:

    function onStateChange() {
        var state = window.History.getState();
        // Handle state accordingly.
    
        // Fetch the data passed with pushState.
        var data = state.data;
        var title = state.title;
        var url = state.url;
    }
    
    // Check the initial state.
    $('document').on('load', onStateChange);
    
    // Listen for state changes.
    window.History.Adapter.bind(window, 'statechange', onStateChange);
    
    // Any data you want to be passed with the state change.
    var stateObj = { variable : 'value' } 
    
    // Change state using pushState()
    window.History.pushState(stateObj, "State name", "/page.html");
    

    The state name is ignored by most browsers. The third parameter is the bit that gets added to the URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIWebView that loads a website. Then in - (void)webViewDidFinishLoad:(UIWebView *)webView I
I have a website that loads lightning fast in Firefox, Chrome, and other browsers,
I have a website that requires a very large background image. The page loads
I have a website that is mainly based on JavaScript. It uses a REST
I have a website that logs in using an STS, then gets a delegated
I have a local website that is Javascript controlled and am loading it in
I have an iframe that loads in a page from my website and I
I have a page, with a navigationbar that loads content, from another page, into
I have created a website that intensively use Ajax to load its contents. I
I have a website that I wish to load in a UIWebView, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.