Back to my page

Developers

How to assign a JavaScript behavior to a tag?

It is tempting to use event handlers in the “old” way - that is, by putting the code directly on the tag's handler, like so:

<textarea onfocus="pieceOfCode(this);" >
  Default text
</textarea>

It is no longer possible to do so in the UWA environment: the pieceOfCode method above would be set globally, like document.pieceOfCode(), which is not allowed in UWA (the document and window objects are not recommended for portability reasons).

It is therefore recommended to dynamically assign the behavior, through JavaScript:

widget.onLoad = function() {
  var textarea = widget.body.getElementsByTagName("textarea")[0];
  textarea.onfocus = function() { ... }
}

This has the added bonus of preventing the cluttering of the HTML code with JavaScript events…

Business

Partner with us.

Developers

Build once, run everywhere.

Community

Get involved, get localized.

Press

News. Media kits. Press releases.