[Twisted-Python] Woven LivePage sendScript works with some scripts but not others

Donovan Preston dp at twistedmatrix.com
Thu Jul 17 22:56:19 EDT 2003

On Thursday, July 17, 2003, at 5:37PM, Tim Andrews wrote:

> Hi twisted,
> I'm trying to use LivePage to send some script to a web page.
> All works well if the script is as per the manual example, ie
> sendScript("alert('Hello world!')")
> will pop up a window as expected.
> However, if i try a script like "document.all.fred.innerHTML='FRED'" I 
> get
> an error on the page "Error: document.all.fred is null or not an 
> object". I
> know the script is okay because if it is on the on the page it will 
> work.
> Any clues?

This is *probably* because, with the version of LivePage you are 
currently using, the JavaScript is evaluated within the context of the 
Output IFrame. I'm not a regular in-browser javascript expert, but 
something like top.document.all.fred or parent.document.all.fred might 
work better for you.

By the way, if you are trying to do your own innerHTML setting, don't. 
Woven LivePage includes a cross-browser abstraction of this sort of 
in-browser DOM mutation. Just write your Widgets in a way that they 
will always render themselves the way you want them to based on the 
Model data and the state of the session. (For example, you could set 
session.color = 'blue' and it would be different from someone else who 
has session.color = 'green')

Then, use one of the MVC notification APIs to cause Woven to re-render 
your Widget and send the appropriate, abstract JavaScript to the 

someWidgetReference. modelChanged({'request': request})


someModelReference.notify({'request': request})

Why the hideous dictionary-with-the-request-in-it? Ancient historical 
reasons which are entirely irrelevant now. I will change it to simply 
take the request asap, but for now, just do that :-)


More information about the Twisted-Python mailing list