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 6787509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:22:29+00:00 2026-05-26T17:22:29+00:00

I’m pretty much a novice when it comes to js so I’m sorry if

  • 0

I’m pretty much a novice when it comes to js so I’m sorry if I’m missing something really simple.

Basically, I’ve done some research into using the history.pustate and popstate and I’ve made it so a query string is added to the end of the url (?v=images) or (?v=profile)…(v meaning ‘view’) by using this:

var url = "?v=profile"
var stateObj = { path: url };
history.pushState(stateObj, "page 2", url);

I want to make it so I can load content into a div but without reloading the page which I have done using the .load() function.

I then used this code:

$(window).bind('popstate', function(event) {
    var state = event.originalEvent.state;

in $(document).ready() section and later tried within just <script> tags and neither worked.

I don’t know how to make it so the content changes when I use the back button or at least makes it so I can trigger my own function to do so; and I’m assuming it has something to do with the state object?! I just can’t seem to find anything online that explains the process clearly.

If someone could help me out it would be amazing and thank you in advance to anyone who does!

  • 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-05-26T17:22:29+00:00Added an answer on May 26, 2026 at 5:22 pm

    The popstate only contains a state when there is one.

    When it goes like this:

    1. initial page loaded
    2. new page loaded, with state added via pushState
    3. back button pressed

    then there is no state, because the initial page was loaded regularly, not with pushState. As a result, the onpopstate event is fired with a state of null. So when it is null, it means the original page should be loaded.

    You could implement it such that history.pushState will be called consistently and you only need to provide a state change function like this: Click here for jsFiddle link

    function change(state) {
        if(state === null) { // initial page
            $("div").text("Original");
        } else { // page added with pushState
            $("div").text(state.url);
        }
    }
    
    $(window).on("popstate", function(e) {
        change(e.originalEvent.state);
    });
    
    $("a").click(function(e) {
        e.preventDefault();
        history.pushState({ url: "/page2" }, "/page2", "page 2");
    });
    
    (function(original) { // overwrite history.pushState so that it also calls
                          // the change function when called
        history.pushState = function(state) {
            change(state);
            return original.apply(this, arguments);
        };
    })(history.pushState);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I don't have much knowledge about the IPv6 protocol, so sorry if the question
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.