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

  • SEARCH
  • Home
  • 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 7028681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:27+00:00 2026-05-28T00:26:27+00:00

first off I can’t seem to figure what the first parameter in the pushState

  • 0

first off I can’t seem to figure what the first parameter in the pushState function is for? What do I pass to it? I simply want to change the url when scrolling through my page. I’m querying the ID of the current element in the viewport and its ID should also be the link in the url. That works fine with the code below.

var currentHash,
        url;

    if (history && history.pushState) {

        $(window).scroll(function() {
            hash = $('.layer:in-viewport').attr('id');
            catHash = $("#"+hash).parent('section').attr('id');

            var data = "nothing";

            if ( catHash != undefined )
                url = "/" + catHash + "/" + hash;
            else
                url = "/" + hash;

            if ( currentHash != hash ) {

                window.history.pushState(data, hash, url);

            }

            currentHash = hash;

        });

    }

Now I have two questions:

1.) Right now the url in the addressbar changes successfully when I scroll through my page. How can I query the url/hash in the addressbar when I initially load the page. So imagine I have now a link like www.url.com/deep I want to find out what /deep is? Do I simply have to query the entire top.location and split it on each “/”? I mean those links are actually not existing, so how do I avoid 404 pages when calling a url that I manipulated with the pushState function?

2.) How can I find out the last change in the addressbar when clicking the back button? So I want to find /deep when clicking on the browser back button so I can navigate back to that position on the page. I guess this is probably working with popstate but I couldn’t find out how!

Thank you for your help!

Update:

window.history.pushState("test", hash, url);

…

$(window).bind('popstate', function(event){
        console.log(event.data);
    });

This is alway null. Shouldn’t this return “test”?

  • 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-28T00:26:27+00:00Added an answer on May 28, 2026 at 12:26 am

    what the first parameter in the pushState function is for?

    From the documentation

    state object — The state object is a JavaScript object which is associated with the new history entry created by pushState(). Whenever the user navigates to the new state, a popstate event is fired, and the state property of the event contains a copy of the history entry’s state object.

    So it is a bundle of data of your choice that you get back when you return to that state.

    Right now the url in the addressbar changes successfully when I scroll through my page. How can I query the url/hash in the addressbar when I initially load the page.

    Look at the location object … but you don’t need to. You can (and should) populate the page server side. This is one of the advantages of pushState, the link still works if JavaScript is not available and the server side fallback is smoothly integrated.

    How can I find out the last change in the addressbar when clicking the back button?

    You add an event listener (looking for a popState event), and the data you stored in it will be available on the event object. MDN has an example

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

Sidebar

Related Questions

First off, I'm not an expert with MySQL queries, and I can't seem to
first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
First off, I can connect to both databases with SQL Server Enterprise Manager, so
First off, I know I can copy "this" on instantiation, but that doesn't work
First off: I know that this isn't reliable for actually checking if I can
First off I'm horrible with regex, hoping I can get some help here cause
First off, let me apologize if this has been asked already, but I can’t
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
First off, I know there are ways to make it so that text can
First off, here's my code: var variable1 = 10; function f1 (){ alert(variable1); }

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.