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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:18:36+00:00 2026-06-05T08:18:36+00:00

For some reason, IE9 is not running my JavaScript code onload when the browser

  • 0

For some reason, IE9 is not running my JavaScript code onload when the browser is launched for the first time that session. It seems to only run onload after the user refreshes the page. It will also run the JavaScript when the debug console is open.

How do I make it so the JavaScript runs onload after the browser is open? Is this just a bug of IE9?

I’ll restate this so you understand: The code DOESN’T run if you go to the site after launching a new browser session. The code DOES run if you open the site in a new tab, or reload the page, or open the debug console

Here is the function I use to run my script onload (which works fine in NORMAL browsers):

(function (i) {
  var u = navigator.userAgent;
  var e = /*@cc_on!@*/
  false;
  var st = setTimeout;
  if (/webkit/i.test(u)) {
    st(function () {
      var dr = document.readyState;
      if (dr == "loaded" || dr == "complete") {
        i()
      } else {
        st(arguments.callee, 10);
      }
    }, 10);
  } else if ((/mozilla/i.test(u) && !/(compati)/.test(u)) || (/opera/i.test(u))) {
    document.addEventListener("DOMContentLoaded", i, false);
  } else if (e) {
    (function () {
      var t = document.createElement('doc:rdy');
      try {
        t.doScroll('left');
        i();
        t = null;
      } catch (e) {
        st(arguments.callee, 0);
      }
    })();
  } else {
    window.onload = i;
  }
})(init); //init is the function to call onload
  • 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-06-05T08:18:38+00:00Added an answer on June 5, 2026 at 8:18 am

    Okay, I figured it out. It has to do with some weird way IE handles IF statements.

    In my init function I had two IF statements, one which checked if a variable existed and then logged the value of that variable. The other which checked to see if the value of the same variable was equal to an arbitrary string.

    After removing the first IF statement, everything seems to work properly. I also decided to use a different onload function which can be seen below:

    if (document.addEventListener) {
        document.addEventListener('DOMContentLoaded', init, true);
    } else if (document.all && !window.opera){ //Crude test for IE
    //Define a "blank" external JavaScript tag
        document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
        var contentloadtag=document.getElementById("contentloadtag");
        contentloadtag.onreadystatechange=function(){
            if (this.readyState=="complete") {
                init();
                //ie('open');
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason this code doesn't work in IE9 (could not try other versions
For some reason I have always assumed that most of the time a variable
For some reason, I was under the impression that it was just called Timeout,
For some reason on my application when running on some configuration of hard disk
For some reason I am not able to use the TextFlow element in WPF.
For some reason, the following code never calls Event::Event(Event&& e) Event a; Event b;
For some reason, I can not seem to change the default position of an
For some reason this basic JS to detect the browser's resolution works in Safari
I'm not sure what's causing the problem, but for some reason sidebar of my
For some reason, I can't get rgba working within my CSS using IE9. I've

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.