[Zope] Re: [Zope-dev] Javascript wizards wanted for Zope project

Martijn Pieters mj@antraciet.nl
Wed, 17 Nov 1999 10:29:41 +0100


I know you have been given many answers, but I'll bud in anyway. I've done 
way too much JavaScript, I like to think I know it's pitfalls.

At 02:45 17/11/99 , Anthony Pfrunder wrote:
>The problem is: how do I get a form to talk to an object in another frame?
>ie:
>
><input value=".." ... onchange="mywidget.setAttribute('property',
>value-of-inputbox)>
>
>where mywidget is a javascript function defined in another (loaded) frame.

You can just refer to it's name via the frameset that defines it, like 
parent.nameofotherframe,mywidget.setAttribute(), but you can never be sure 
that the other frame has been loaded.

To get around this problem, I use an asynchronous message broker in the 
parent frame. The calling frame checks for a boolean property on it's 
parent to check wether or not it is capable of doing the messaging, then 
calling a method on this parent that'll pass on the message to the 
receiving frame:

   onLoad="if (parent.bIsTop) parent.setMenu('foo')"

The receiving frame sets a boolean flag on the same parent frame to signal 
it is ready to receive messages:

   onLoad="if (parent.bIsTop) parent.bNavLoaded = true;"

You can now use setTimeout, and a counter, to pass the message on. As long 
as bNavLoaded (the flag indicating messages can be passed on) is false, and 
we haven't tried too many times yet, wait a specified time and try again.

A real life example using two way message passing is used on 
http://www.marantz.com/, in both the Hifi and Professional sections 
(altough I don't think the Professional section is live yet).

In the Hifi section, the navigation frame signals the right hand frame on 
mouse-over events to show descriptions of the menu choices, and the right 
hand frame, when deeper into the site, signals the navigation frame to tell 
it what menu option to display. This way the user can use te back and 
forward buttons of his browser to step through it's browsing history, and 
the navigation menu follows suit.

>Also, how can I "call" a html page without causing a reload:
>
>function jsZDOMsetAttribute(name, value){
>   call("getWidget/setAttribute?name=name&value=value")
>}
>
>For further information on this problem please see
>http://163.182.196.200/zwiki/VisualZope - jsZDOM reflecter part.

For this one you'll need a hidden frame (width or height of 0), or you 
could use a hidden DynDuo Layer and use it's load method:

   http://www.dansteinman.com/dynduo/en/dynlayer-common.html

You should be able to then also read attributes from the server with this. 
Just have the server return a page with javascript in it that does the 
trick. Just remember, that you cannot wait for the page to load and expect 
it to return a value, you'll have to write something asynchronous (and 
non-blocking, Navigator's Javascript implementation is single threaded, use 
setTimeout) to retrieve the value.

--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------