[Javascript] Handle several window.onload functions

Guillaume javascript at webdesignofficina.com
Tue Jul 5 16:14:29 CDT 2005



Hello Travis, nice to meet you too.

Ok, here is for example, one function i use at the end of a separate 
file.js:

window.onload = init;


Here is another function that is triggered from inside the content page.htm:
<a href="#" onclick="obj.slideTo(0, -200, 1000, -.6); return false;">
I'd like to separate this from the content page, put it in a separate 
.js file and call this using a class="onclick"
Inside the content page the link would then become something like <a 
href="#" class="onclick">
And here is the JavaScript i plan to use:

|function onClickSlide() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("onclick")) {
      links[i].onclick = function() {
        |obj.slideTo(0, -200, 1000, -.6);
|        return false;
      }
    }
  }
}
window.onload = ||onClickSlide||;

|

Now i have two window.onload to deal with...

window.onload = init;|
window.onload = ||onClickSlide||;| 


...wich will cancel each other, right ?

I'd like some help, point me to a ressource, or help me to build a 
global window.onload function wich could be

|function globalWindowOnload() {

|window.onload = init;|
window.onload = ||onClickSlide||;| 
|||return false;
     
}
window.onload = ||globalWindowOnload||;

|

This is the very basic concept and i'm sure it won't work this way...
Could help me to refine this idea ?

Thanks.

Guillaume.
||

||||




> Hi Guillaume,
> Great to meet you.  From my experience people on this list answer 
> things more often when code snippets accompany a question.  I think I 
> know what you are asking but that would really help to clarify.  Thanks.
>
> *Travis D. Falls* | Consultant   RAFT.Net   IT | 860.547.4070 | 
> travis.falls at thehartford.com
>
>     -----Original Message-----
>     *From:* javascript-bounces at LaTech.edu
>     [mailto:javascript-bounces at LaTech.edu]*On Behalf Of *Guillaume
>     *Sent:* Tuesday, July 05, 2005 4:22 PM
>     *To:* [JavaScript List]
>     *Subject:* [Javascript] Handle several window.onload functions
>
>
>     Hi list,
>
>     This is my first post here so let me introduce myself briefly: my
>     name is Guillaume and i'm working as a freelance webdesigner
>     in Paris, France.
>      I was told elsewhere, the css-d mailing list, by a very nice guy,
>     Roger Roelofs, who helped me a lot on some JavaScript issues, that
>     this was a great list to ask for help. I've been using JS since
>     the very begining of my activity on the web but my skills are
>     limited to change scripts that are already built, not to build
>     them from the scratch.
>     So here i go:  I focused a lot this last year on Css and
>     Accessibility. I recently discovered the concept of "Unobtrusive
>     Javascript" and try now to separate completely the JS i use from
>     the document content. The problem i encounter is that i use
>     several window.onload for the same document, wich cancel each
>     other called separately. I'd like to build a global window.onload
>     function, in wich i could add a list of different functions I fire
>     up with window.onload.
>     I actually thought this would be easy... Apparently not when i
>     read Simon Willison's weblog about this subject in an article
>     called "Executing JavaScript on page load"
>     <http://simon.incutio.com/archive/2004/05/26/addLoadEvent>
>     I'm unable, don't have the skills, to choose carefully for a valid
>     method when i read this article and the multiple comments related.
>     So can this problem be solved by a simple way, cross-browser,
>     robust method ?
>     Could someone point me to a simple ressource, or help me on this
>     problem ?
>     Thanks.
>     Guillaume
>
>
>
> *************************************************************************
> PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is
> for the exclusive use of addressee and may contain proprietary,
> confidential and/or privileged information. If you are not the intended
> recipient, any use, copying, disclosure, dissemination or distribution is
> strictly prohibited. If you are not the intended recipient, please notify
> the sender immediately by return e-mail, delete this communication and
> destroy all copies.
> *************************************************************************
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>  
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050705/cccc3d4b/attachment.htm>


More information about the Javascript mailing list