<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="Hello" title="Hello" orient="horizontal" width="250" height="100" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> </window>If we show this XUL file, we will have this empty window:
<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="Hello" title="Hello" orient="horizontal" width="250" height="100" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <button label="Push Me!" /> </window>We now have the window with a button:
oncommand
attribute to the button to listen to the button clickoncommand
attribute: <?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="Hello" title="Hello" orient="horizontal" width="250" height="100" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <button label="Push Me!" oncommand="clicked()" /> </window>But of course there is no script yet so the
clicked()
is not handled. If we click on the button, the following error popup appears:clicked()
. Let's add this script:<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <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(){ alert('Hello World!'); } </script> <button label="Push Me!" oncommand="clicked()" /> </window>Now we created a script. If we click on the button, the
clicked()
function will be called. The result of the function is now to show a popup:Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence