[Zope] Calling external method from javascript

Laura McCord Laura.McCord at doucet-austin.com
Wed Sep 29 14:12:27 EDT 2004


This is where I am at right now. I wrote a javascript function
loadZopeMethod() and I tried it by itself and it works. But I tried what
you suggested:

tal:attributes="onclick string:showObject(event, '${box}');
jsRoutine2(); jsRoutine3();"

<A href="javascript:;" tal:attributes="onclick string:showObject(event,
'${box}'); loadZopeMethod();">MACAddress Table</a>

This does not work. Did I do something wrong?

BTW thanks for your time.
 Laura

-----Original Message-----
From: Jonathan Hobbs [mailto:toolkit at magma.ca] 
Sent: Wednesday, September 29, 2004 10:08 AM
To: Laura McCord; zope at zope.org
Subject: Re: [Zope] Calling external method from javascript


From: "Laura McCord" <Laura.McCord at doucet-austin.com>
>  I am having trouble with this part of my program. I have an onclick 
> function that needs to perform three things. I know that I should have

> a javascript function that basically handles these three operations, 
> but I don't know how to call an external method from javascript. I am 
> using a zope page template if that helps. I have googled on this topic

> and there is not a lot said about this situation. I did run across 
> someone using dtml and calling dtml methods from javascript but did 
> not see any examples on using it with zope page templates.
>
> Typically I would call a external function like this: <div 
> tal:content="python:here.deleteMAC()"> but this won't work.

AFAIK javascript can not call a zope method (dtml, script or external
method) directly, javascript has to do indirectly by loading a url into
the browser.  You can load into a window, frame, div, etc. Here is an
example:

displaywindow.location.href = '<dtml-var
baseurl>DisplayPage?id='+presentorpage+'&stype='+pagetype+'&path='+pagep
baseurl>ath

This one line of javascript will load a zope routine called DisplayPage
(with a url path specified by a dtml variable called baseurl) into a
browser window named 'displaywindow'.  It also passes some parameters
(id, stype,
path) to the zope routine.

If you need to communicate between the client process (running in the
users
browser) and the server process (ie a zope routine) without the user
seeing anything, you can accomplish this using a hidden div in your html
(use javascript to load the url (containing your call to the external
method) into the hidden div), this will allow you to call a zope routine
and get some results without changing the user's browser's display. The
zope routine you call (via the hidden div) can return javascript
variables which you can then parse to determine what you want to do next
(embed an 'onload' javascript command in the html returned by the zope
routine to cause a javascript routine to execute after the hidden div is
loaded).

HTH

Jonathan





More information about the Zope mailing list