Software As She’s Developed

Mahemoff’s Podcast/Blog - Web, Programming, Usabilty from the Author of ‘Ajax Design Patterns’ (AjaxPatterns.org)

Software As She’s Developed header image 2

Dojo Gotcha - Initialization with window.onload

June 25th, 2006 · 1 Comment

I've been playing with Dojo, specifically the rich text editor, and came across a Gotcha in setting up the whole thing, which isn't documented too clearly. Specifically, Dojo needs its own window.onload - if you have your own window.onload (as you probably do if you need any initialisation), it will conflict with Dojo!!!

The solution is described here (though it seems Dojo changed a property name a few months ago, from baseRelativePath to baseScriptURI). This is working for me - in my HTML:

HTML:
  1.     <title>My App</title>
  2.     <script type='text/javascript'>
  3.             var djConfig = {
  4.             baseScriptURI: "/ddq/js/dojo/",
  5.           isDebug: true
  6.         };
  7.     </script>
  8.      <script type="text/javascript" src="/javascripts/dojo.js"></script>
  9.      <script type="text/javascript" src="/javascripts/myapp.js"></script>
  10. </head>


In myapp.js:

JavaScript:
  1. dojo.require("dojo.event.*");
  2. dojo.event.connect(window, "onload", myappInit);
  3.  
  4. function myappInit() {
  5.     alert("Okay, here we are in the old window.onload and it's still running :-)");
  6. }


It might be a good idea for the Dojo crew included some explanation of this in the standard heres-how-to-setup-dojo.js-intro docs. Maybe someone with in-depth knowledge of Dojo could infer that window.onload must be used by Dojo, but the average programmer taking Dojo a spin won't.

Links:

Dojo. Awesome framework. Bring on the doco.

Categories: SoftwareDev

Tags:

1 response so far ↓

  • 1 Joe // Oct 20, 2006 at 10:52 pm

    You saved my life!

    Thanks,
    Joe

Leave a Comment