IntroductionInstallationLimitations of the "file" protocolFrequently asked questionsSyntax, keywords and built-in functionsStandard distributionimport implementationBrython packagesBrowser interface
Introduction - DOM API
Creating a document Accessing elements Attributes, properties and methods Events Mouse events Keyboard events Focus events Drag events Query string Interactions with Javascript Brython-specific built-in modules
browser
browser.aio browser.ajax browser.html browser.local_storage browser.markdown browser.object_storage browser.session_storage browser.svg browser.template browser.timer browser.webcomponent browser.websocket browser.worker Widgets browser.widgets.dialog browser.widgets.menu interpreter javascript Working with BrythonCookbook |
ProblemRead the content of a fileSolutionWe use the built-in functionopen() to load the file content
import time
from browser import ajax, document
def on_complete(req):
if req.status==200 or req.status==0:
document["zone"].value = req.text
else:
document["zone"].value = "error "+req.text
def err_msg():
document["zone"].text = "server didn't reply after %s seconds" %timeout
timeout = 4
def go(url):
req = ajax.Ajax()
req.bind("complete", on_complete)
req.set_timeout(timeout,err_msg)
req.open('GET',url,True)
req.send()
go('file.txt?foo=%s' %time.time())
|