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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:46:15+00:00 2026-05-28T02:46:15+00:00

I have strange problem for which I can’t think of a solution. I have

  • 0

I have strange problem for which I can’t think of a solution. I have written some Javascript code to load some content through a AJAX call which also does some animation. To make the website functional I use jQuery with History.js. This is the script:

(function (window, undefined) {
    getContent(true); // Function that gets the initial content via AJAX and does some animation
                      // The parameter specifies that the call to the function is onload

    History.Adapter.bind(window,'statechange',function(event){ 
       getContent(); 
    });

    function getContent(onload){
       if(onload == true){
         // Do onload stuff. Only slightly differs from other event calls
         // If there is no state given define default one ie 'home'
         alert('onload event triggered'); // For debug purposes
       } else {
         // Do other event stuff
         alert('click event triggered'); // For debug purposes
       }
     }

    somelinks.on('click',a,function(){ // Setup some eventlisteners that push the state });

})(window);

In browsers that support the HTML5 History/State API (Firefox, Chrome) this works flawless. On a load or reload of a specific url or on a click event the function does its work.

In IE it also works (with hashes ofcourse), however when I reload a page (ie example.com/#/test) the first as well as the second ‘getContent()’ function. So in Firefox a reload triggers the onload event alert, but in IE the onload event and the click event alert are triggered.

What I need is a way of structering my code or a logical check to prevent IE from calling the second getContent(). I’ve searched for similar problems (keywords: IE, History.js, etc.) but nothing to be found.

Hope somebody can help me with the 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-28T02:46:16+00:00Added an answer on May 28, 2026 at 2:46 am
    (function (window, undefined) {
    
        var getContentOK = true;
    
        getContent(true);
    
        History.Adapter.bind(window,'statechange',function(event){
           getContent(false);
        });
    
        function getContent(onload){
           if (getContentOK === true) {
    
               if(onload == true){
                   // Do onload stuff. Only slightly differs from other event calls
                   // If there is no state given define default one ie 'home'
                   alert('onload event triggered'); // For debug purposes
               } else {
                   // Do other event stuff
                   alert('click event triggered'); // For debug purposes
               }
    
               getContentOK = false;
               setTimeout(function () {
                   getContentOK = true;
               }, 500);
           }
         }
    
        somelinks.on('click',a,function(){ // Setup some eventlisteners that push the state });
    
    })(window);
    

    This will throttle the statechange event handler to only run getContent() once every 500ms.

    Notice that I added some boolean flags, one to throttle the statechange event handler and one to mimic your onload variable. firstRun will output true on the first run and then false on each subsequent runs.

    This is not as good a solution as figuring out what is happening with the History.js plugin but I have no experience with it so I can’t say why IE is firing two events.

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

Sidebar

Related Questions

I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
I have a strange problem with BASH script which I can't figure out. I
I've got a strange problem which I just can't figure out. I have currencies
Everybody out there, I'm writing a c code which have a strange problem when
I have a strange problem with tortoise git at the moment, which I can't
I have a strange problem which I have been trying to fix for some
I have got a strange problem about in_array recently which I cannot understand. e.g.
I have a strange problem with VS2008. My solution has 8 projects (all c#)
I have a strange problem with some documents on my webpage. My data is
I have a graffiti blog and i have a strange problem which is showing

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.