replacement for onload?

Discussion in 'JavaScript' started by andre75, Oct 9, 2006.

  1. #1
    I have downloaded some example code from cj.

    It has a piece of javascript that defines a function (loadKeywordAds) and it calls this function in the body tags like this:
    <body onload="loadKeywordAds('placeholder');">
    Code (markup):
    Since I only want to use it on certain pages, I am trying to find alternatives that lets me paste a piece of html (or php) that does the same thing somewhere else on the page.
     
    andre75, Oct 9, 2006 IP
  2. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    window.addEventListener('load', function() {
      loadKeywordAds('placeholder');
    }, false);
    
    Code (markup):
    Grab this if you want to use event listeners in both IE and W3C event model-compliant browsers.
     
    penagate, Oct 10, 2006 IP