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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:05:36+00:00 2026-05-30T14:05:36+00:00

I have the following code and the second onload event is not firing: <script

  • 0

I have the following code and the second onload event is not firing:

    <script type="text/javascript">
    var startime = (new Date()).getTime();

    window.onload = function(){ record_visit('ol'); } //ol - onload
    window.onload = function(){ setInterval("upState()", 30000); }
    window.onbeforeunload = function(){ record_visit('obul'); } //obul = onbeforeunload

    function record_visit(value) {
        var x = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        x.open("GET", "count_visit.php?t=" + (((new Date()).getTime() - startime) / 1000)+"&type="+value+"&url="+escape(window.location.href), false);
        x.send(null);
    }

    function upState()
    {
        // create the AJAX variable
        var xmlhttp;
        if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
        else
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        // make the AJAX call
        xmlhttp.open("GET", "count_visit.php?t=" + (((new Date()).getTime() - startime) / 1000)+"&type=update&url="+escape(window.location.href), false);
        x.send(null);
    }   
</script>

All I need here is to send request using count_visit.php and update the table that the visitor is still online.

I tried some code I found in some site but still it’s not firing. here’s the code:

    function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(record_visit('ol'));
addLoadEvent(setInterval("upState()", 30000));

Any help please.

  • 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-30T14:05:38+00:00Added an answer on May 30, 2026 at 2:05 pm

    With the second window.onload you are overwriting the one that was defined before. As you are not using jQuery (which makes these things easier) use the following function

    function myEvent(where,evt,func,op)
    {
     if (op)
      {
       if (where.attachEvent) where.attachEvent("on"+evt,func);
       else if (where.addEventListener) where.addEventListener(evt,func,false)
      }
      else 
      {
       if (where.detachEvent) where.detachEvent("on"+evt,func);
       else if (where.removeEventListener) where.removeEventListener(evt,func,false);
      }
    }
    

    where – object where you are adding your event listener to

    evt – the name of the event (without ‘on’ part)

    func – function to be called on event

    op – if it is set to true the function will add listener and if it is set to false the function will remove listener.

    Call it as myEvent(window, 'load', func, true); And does not matter how many functions you add – all of them will be called at the given event.

    ps: or you can just combine the content of both functions manually :))

    window.onload = function(){ 
          record_visit('ol'); 
          setInterval(upState, 30000); 
    }
    

    using this method you have to check the existence of the previous event handler, save it in some global variable and call it later when you will be dealing with execution of the final and the only one window.onload function. You were trying to do it in the last portion of the code.

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

Sidebar

Related Questions

I have the following javascript code: <script type=text/javascript> var x = 10; window.onload =
I have following code (live: http://jsfiddle.net/xyZY8/1/ ): var str = '<div>hello</div><ul><li>Some text...</li>' + '<li>second
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have the following code to tabhost. tabHost.addTab(tabHost.newTabSpec(tab1) .setIndicator(First Text) .setContent(new Intent(this, class1.class))); tabHost.addTab(tabHost.newTabSpec(tab2)
I have the following C# code below. Object first = 5; Object second =
I have following code class User attr_accessor :name end u = User.new u.name =
When I'm trying to run the following code in IE:- <html> <head> <script language=javascript>
I have the following code written to make my lazy second CPU core working.
So I have the following code where I should read a Text File (This
I have the following code: http://jsfiddle.net/dbg5X/ Is it possible to have the second div

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.