Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem Adding javascript function calls during onload page event

    I have the following javascript function:

    [ function addNewWindowEvent(evType, fn)
    {
    if (window.addEventListener)
    {
    this.addEventListener("load", fn, false);
    return true;
    }
    else if (window.attachEvent)
    {
    var onload = "onload"
    this.attachEvent(onload, fn);
    return true;
    }
    else
    {
    return false;
    }
    } ]

    which is giving me a an exception every time a page on our site loads. The actual exception in firefox is this:

    uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: https://cms-dev.stchas.edu/global/js/hdvscripts.js :: addNewWindowEvent :: line 5" data: no]

    and I'm not sure exactly what it's complaining about. I'm relatively new to javascript so diagnosing and fixing this problem has me quite puzzled, and so far I have been unable to find anything helpful when I try and google for information on this. I would appreciate any help or suggestions. Thanks.

    henryv

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,971
    Thanks
    15
    Thanked 229 Times in 229 Posts
    Right before the close body tag, the one with the / , make a script tag and but all the function calls you want to make in it in proper order. If the functions are called one only time you can put the function calls for one function in another. You can also make a new function with all the calls in it, in proper order, and call it with window.onload = function().

  • Users who have thanked DrDOS for this post:

    henryv (11-11-2010)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •