[Seaside] javascript window.onLoad not called

Lukas Renggli renggli at gmail.com
Sun Mar 25 07:31:18 UTC 2007


> Hi. My problem is that Seaside isn't calling a javascript window.onload
> event handler. I've defined this handler in a javascript file like this:
>
> window.onload = function(e) {
>    var cookie = readCookie('mycookie');
>    var title = cookie ? cookie : getCurrentTitle();
>
>   alert('hi this isn't working');
>    setCurrentTitle(title);
>  }
>
> window.onunload = function(e) {
>   var title = getActiveTitle();
>   createCookie('mycookie', title, 365);
> }
>
> Then I've made a #script method in a WAExample class with the contents of
> this .js. I need the framework to call the onLoad event and execute that
> function, but when I enter the pages nothing happens. This is the expected
> behavior? Should I add something else to my component?
> I'm using Seaside2 (2.7a1.mb210).

The problem is that you directly assigning a function to onLoad using
Javascript: Seaside defines its own onLoad attribute in the body-tag
and therefor overrides your code. Have a look at
http://www.quirksmode.org/js/events_tradmod.html to learn about the
problems with your approach.

Better use the approach shown here
http://www.quirksmode.org/js/events_advanced.html or one of the
convenience methods several libraries like Prototype or Mootools
provide.

Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch


More information about the seaside mailing list