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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:33:22+00:00 2026-05-28T14:33:22+00:00

With HTML5 History API, I created something like below: (function (d, w) { $(function

  • 0

With HTML5 History API, I created something like below:

(function (d, w) {

    $(function () {

        $("#indicator").hide();

        if (typeof history.pushState !== 'undefined') { 

            $("#citylinks a").click(function (e) {
                history.pushState({ path: this.href }, '', this.href);
                act(this.href);
                e.preventDefault();
            });

            w.onpopstate = function (event) {
                act(d.location);
            };
        }

        function act(location) {

            $("#results").hide();
            $("#indicator").show();

            $.getJSON(location, function (data) {

                $("#results").html(data.result);
                $("#results").fadeIn();

                $("#indicator").hide();
            });
        }

    });

})(document, window);

The complete code is here:

https://github.com/tugberkugurlu/MvcMiracleWorker/commit/7c511f20678bbfe15462909c794eb323ce615372#diff-3

The problem I have here is that I do not want to fire the w.onpopstate event at the first time page comes from the server.

The reason I would like to do this is that I would like to fill the page at the server side and I do not want client side code to do that. If I remove w.onpopstate event, I won’t be able to catch history.go() events.

Is there any way to solve this problem?

  • 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-28T14:33:23+00:00Added an answer on May 28, 2026 at 2:33 pm

    A very simple approach would be this:

    w.onpopstate = function () {
        w.onpopstate = function (event) {
            act(d.location);
        }
    }
    

    This means that the first time the onpopstate event fires, your function is set to the event handler (replacing the current handler), effectively creating a noop for when the event runs on page load.

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

Sidebar

Related Questions

Is there any way to use HTML5 History API ( pushState ) in IE9?
Is there any way to check a browser whether it supports 'HTML5 History API'
How do i use HTML5 history api. I did go through the https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history .
I have a site like: http://*mysite.com/search/ in it index.php is generating History.pushState() for history.js
The new Github HTML5 and CSS3 (HTML5 History API) tree navigation is great: https://github.com/blog/760-the-tree-slider
So, after redesigning my site, I thought I would use the HTML5 history API,
I started looking at HTML5 new history API However, I have one question. How
I would like to use the HTML5 window.history feature to implement full AJAX navigation
HTML5 draft contains an API called EventSource to stream data (notifications) trough javascript using
I have the following HTML5 content: <section contenteditable=true id=editable class=ui-selectee ui-selected> <span>something</span> <span>something</span> <span>something</span>

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.