SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33
  1. #26
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  2. #27
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have now been given a page that uses other javascripts that I need use all together. unfortunately one of these pages is killing the code. I have been through and narrowed the exact javascript file that is killing it.

    any advise on how to find which part of the script is affecting the one i want to use??

  3. #28
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The other Js may also be assigning a function to "window.onload". As a test, go back to using xOnLoad.

  4. #29
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    apologies for the long break in posting.

    I narrowed the problem down to one other .js file, and yes it uses a "window.onload = __dnn_Page_OnLoad;"

    unfortunately this file is a key file in the CMS being used so no removing it - although I might be able to modify it.

    So now I am researching how to run multiple functions with window.onload or run other functions.

    hope you can give me some direction or pointers.

    Cheers.

    P.S. I have tried using the xOnload and it didn't work
    PP.S I am also using both scripts, one with radio button and one with a select box, for different pages that both use the other .JS

  5. #30
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xOnLoad is not a magic pill - in fact it is very simple and you have to use it in the right place and in the right way.

    If this line:

    window.onload = __dnn_Page_OnLoad;

    comes "after" your call to xOnLoad, then you can see that it won't work that way.

    either use xOnLoad for both,
    or include your js files in the proper order,
    or call __dnn_Page_OnLoad as well as your own initialization routine in your own onload handler.

    Since I can't see the page I don't know what else to say.

  6. #31
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No that helps a bit.

    They are in separate .js files so I am assuming that is a major problem from the start.

    I am also trying to see if I can write this to work with some sort on "onchange" within the page so that I don't need window.onload , please tell me if i am dreaming lol.

    How do I combine xonload for both? I am pretty sure I can't do this though as i may not be allowed to modify the offending .js file.

  7. #32
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use the AddEventListener/AttachEvent function to add a second onload event handler (that runs after the original one). Sounds like that's what you need.

    Using Mike's xAddEventListener makes life easier (I split up the example into 3 <script> sections to simulate the use of external js files.)
    Code:
    <html>
    <head>
    <script type="text/javascript">
    // this script uses window.onload and we are not allowed to change it
    // this could be coming from an external js file, the important thing is that it's declared FIRST
    
    window.onload = function () {
    	alert("original onload");
    }
    </script>
    <script type="text/javascript">
    // mike's x function with dependency to xGetElementById removed for simplicity
    // this could/should be in an external JS file
    
    function xAddEventListener(e,eT,eL,cap)
    {
      eT=eT.toLowerCase();
      if(e.addEventListener)e.addEventListener(eT,eL,cap||false);
      else if(e.attachEvent)e.attachEvent('on'+eT,eL);
      else e['on'+eT]=eL;
    }
    </script>
    <script type="text/javascript">
    // code to add another listener that fires after the original onload but still fires onload
    
    xAddEventListener(window,"load",myFn,false);
    
    function myFn() {
    	alert("new onload");
    }
    </script>
    </head>
    <body>
    some html
    </body>
    </html>

  8. #33
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent, Jim!


Bookmarks

Posting Permissions

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