How to make this body onload=?

Discussion in 'HTML & Website Design' started by mustaineoz, May 15, 2007.

  1. #1
    I have 1 script between <head> </head>

    ---------------------------------------------------------------------------
    <script type="text/javascript">
    function(){
    if(!NiftyCheck())
    return;
    RoundedTop("div#nav li","transparent","#0099FF");
    }
    </script>
    --------------------------------------------------------------------------

    and i have another onload which is <body onload="InitPlayer();">

    like this niftycheck is not working!How can i fix this problem?
     
    mustaineoz, May 15, 2007 IP
  2. DatR

    DatR Peon

    Messages:
    210
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well firstly the function needs a name

    so this:
    
    function(){
    
    Code (markup):
    should be like
    
    function InitPlayer() {
    
    Code (markup):
    that may not fix it but you can't have a function with no name
     
    DatR, May 15, 2007 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    
    <script type="text/javascript">
    window.onload = InitPlayer;
    
    function InitPlayer() {
      if(!NiftyCheck()) {
        return;
      }
      RoundedTop("div#nav li","transparent","#0099FF");
    }
    
    …
    
    </script>
    Code (markup):
    cheers,

    gary
     
    kk5st, May 15, 2007 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    Not quite true. There is something called an anonymous function, i.e., no name.

    For example, you might set the onclick handler so that certain links will cause a new window to open for the target url.
    
    window.onload = addhandler;
    
    function addhandler() {
      if (! document.getElementsByTagName) {
        return false;
      }
      var links = document.getElementsByTagName("a");
      for (var i = 0; i < links.length; i++) {
        if (links[i].rel == "ext") {
          links[i].onclick = [color=red]function()[/color] {
            return ! window.open(this.href);
          }
        }
      }
    }
    Code (markup):
    cheers,

    gary
     
    kk5st, May 15, 2007 IP