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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:40:21+00:00 2026-05-21T11:40:21+00:00

I’m trying to figure out how to use HTML5’s history functions. Here’s my basic

  • 0

I’m trying to figure out how to use HTML5’s history functions. Here’s my basic code:

$(document).ready(function () {
    var stateObj = { foo: "bar" };
    history.pushState(stateObj, "page 2", "bar.html");
    console.log(history.state);

    $(window).bind('popstate', function(e) {
            console.log(e.originalEvent);
    });
});

I’m using Jquery 1.5.1. Here’s the console output:

undefined

PopStateEvent
bubbles: false
cancelBubble: false
cancelable: true
clipboardData: undefined
currentTarget: DOMWindow
defaultPrevented: false
eventPhase: 2
returnValue: true
srcElement: DOMWindow
state: null
target: DOMWindow
timeStamp: 1300966328992
type: "popstate"
__proto__: PopStateEvent

I have two questions:

  1. Why is the history.state undefined? Even in the popstate event nothing exists.
  2. Why is popstate even called?! I never pressed back or forward. This is on the first load.

Hopefully somebody can shed some light on this for me.

Thanks in advance!

Sean

  • 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-21T11:40:22+00:00Added an answer on May 21, 2026 at 11:40 am

    According to the FF team, history.state and not firing popstate on page-load are features of their browser.

    Here’s a quote from their notes, at http://hacks.mozilla.org/2011/03/history-api-changes-in-firefox-4/

    • Always expose the current state through a window.history.state property. This way a page immediately gets access to the current state of the page and doesn’t have to wait until the first popstate event fires.
    • Don’t always fire a popstate event right after the load event.
      Instead, only fire it during real session history transitions (i.e., when the user clicks Back or Forward or when history.back()/forward()/go() is called)

    No matter the feature, it is frustrating when vendors split hairs on implementation. Thankfully you can handle the difference easily enough, by simulating the specification and firing your own popstate event on pageload.

    Something like this should work in FF4 using jQuery. You would use this code after binding your event handlers.

    $(document).ready(function () {
      if (history.pushState && typeof history.state !== 'undefined') {
        $(window).trigger({
          type: 'popstate',
          state: history.state
        });
      }
    });
    

    This approach does favor the specification, but it consolidates state management to your handler function(s), instead of an initialization routine; which is easier to maintain. Honestly, I appreciate history.state, but it is superfluous as it’s only useful during page load; otherwise it becomes another variable storage mechanism.

    On a similar note, avoid calling pushState() initially. States are not a kind of variable and shouldn’t be used as such. I only recommend setting the state while responding to a user action – that is after the page/app loads.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.