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 |
ProblemStore objects locally, using HTML5 Local StorageSolutionBrython provides a built-in modulebrowser.local_storage that stores string
values associated to string keys
Store value in input fieldfrom browser import document as doc from browser.local_storage import storage storage['brython_test'] = doc['zone'].value Show stored valuefrom browser import alert from browser.local_storage import storage alert(storage['brython_test'])If a Python object can be serialized by the json module, you can store the
serialized version, then retrieve the original object :
from browser import alert from browser.local_storage import storage import json a = {'foo':1,1515:'Marignan'} storage["brython_test"] = json.dumps(a) b = json.loads(storage['brython_test']) alert(b['foo']) alert(b['1515'])Beware that json converts dictionary keys to their string value, this is why
we use b['1515'] instead of b[1515]
|