I need to be able to i) read a cookie when the page loads, and ii)
save data into the cookie when the page unloads (i.e. when the user
clicks and navigates to another page, within the same site or to a
different site).

I have working code (in a catalyst web application) using <body
onload="readCookie();" onunload="saveCookie();">.
However, we want to move this code out of the <body> element, so we
can only use it in some pages (the <body> tag is added by a global
template for the site). So I started playing around with prototype's
event.observe ... and can't get it to work.

I just cooked a minimal test page to check what the problem might be,
and can't figure out what I'm doing wrong.
I'd appreciate any help or direction ...

Test page:
  <head><title>event.observe test</title>
    <script type="text/javascript" src="prototype-1.6.1.js"></script>
    <script type="text/javascript" language="JavaScript">
      Event.observe('bodyid', 'load', function show1() { $
('div1').toggle() });
      // have also tried document.observe("dom:loaded", function
show1() { blah blah } );
      // as well as
      // Event.observe('body', 'load', function show1() { $
('div1').toggle() });
      // Event.observe('bodyid', 'onload', function show1() { $
('div1').toggle() });
      // etc.

  <body id="bodyid">


  <div id="div1" style="display: none">
    <p>hello world</p>


When loading this page, 'hello world' is never displayed. The
javascript debugger (chrome, firebug) show no errors.
Tested on Chrome (6.0.422.0), Firefox 3.6.3, Opera 10 (build 4585),
all on Ubuntu 10.04 (Lucid, i386).

What is the problem with my code?

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to