Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

XUL Javascript scripts



Javascript scripts in XUL files allow to listen to widget events, or modify XUL widgets attributes. Javascript scripts are more tightly integrated than other scripting languages and therefore have additional capabilities.

Implementation

Javascript scripts are implemented with the Rhino library.

Accessing the document

Additionnally to the getCurrentDocument() method which can used through the helper, it is possible in javascript to use a much more "Javascripty" way to work on the document by simply working with the document objet. It is then possible to access any widgets with IDs on the document and read or modify their properties. For example:
      <window id="Hello" title="Hello" orient="horizontal" width="250" height="100"  
      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">        
          <script> 
      function clicked(){
        document.getElementById("theLabel").value = "NewText";
      }
          </script>         
          <button label="Push Me!" oncommand="clicked()" />
          <label id="theLabel" label="TheText" />
      </window>

MIME types

The MIME types supported for Javascript scripts are:
  • "text/javascript"
  • "text/ecmascript"
  • "application/javascript"
  • "application/ecmascript"
  • "application/x-javascript"

Import declarations

There are two types of import declarations for Javascript:
  • Class import declarations. For example:
                importClass(java.util.List);
    
                function computeSize(list) {
                  return list.size();
                }
    
  • Package import declarations. For example:
                importPackage(java.util);
    
                function computeSize(list) {
                  return list.size();
                }
    
The Javascript print built-in function will call the echo method of the XUL ScriptContext.

For example:
      function clicked(){
        print("You clicked the button");
      }      

Alert built-in function

By default, the Javascript alert built-in function will show a Popup with the alert message.

For example:
      function clicked(){
        alert("You clicked the button");
      }      

See also


Categories: builtin-applis

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence