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

Tim Andrews tim.andrews at adpro.com.au
Thu Jul 17 20:37:23 EDT 2003

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?



Some example code for your perusal ...

from twisted.web.woven import page, controller, interfaces

model = {
    'name': 'LivePage Handled Events',
    'link': 'http://link',

template = """
     <h3> Watch me change! </h3>
     <div id = "fred"> blah </div>
     <h3 model="name" view="Text"/>
     <div model="link" view="Link" controller="foo">mouse here won't work
     <span view="webConduitGlue" />
     <h3>Locally Handled Events</h3>
     <a href="http://link"
        onmouseout="document.all.fred.innerHTML='fred'">mouse here will work

class fooController(controller.Controller):

  def handle(self, request):
    global currentPage
    currentPage = request.getSession(interfaces.IWovenLivePage)
    self.view.addEventHandler("onmouseover", self.foo_onMouseOver)
    self.view.addEventHandler("onmouseout", self.foo_onMouseOut)

  def foo_onMouseOver(self, request, widget):
    global currentPage
    print 'foo over'
    currentPage.sendScript("document.all.fred.innerHTML='FRED'") # :( this
doesn't work
    # currentPage.sendScript("alert('Hello world!')") # :) this works

  def foo_onMouseOut(self, request, widget):
    global currentPage
    print 'foo out'
    currentPage.sendScript("document.all.fred.innerHTML='fred'") # :( this
doesn't work

class fooPage(page.LivePage):

  def wcfactory_foo(self, request, node, model):
    return fooController(model)

resource = fooPage(model, template=template)

More information about the Twisted-Python mailing list