简体   繁体   中英

XUL and Javascript

I have the following XUL markup:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="275" title="Placeholder"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"  xmlns:pen="http://www.pentaho.org/2008/xul" onload="mainToolbarHandler.init()">
  <script type="text/javascript">
  function sayHello(txt) {
    alert(txt);
  }
  </script>  
  <toolbar id="mainToolbar">
    <toolbarbutton id="logout" image="mantle/images/new_report_32.png" onclick="sayHello('hello')"  tooltiptext="Logout"/>
  </toolbar>
 </window>

I'm trying to get the JavaScript function sayHello() to work when the toolbarbutton logout is clicked however nothing occurs and no JavaScript errors occur as well.

Does anyone know how to get JavaScript working with XUL?

Thanks in advance!

尝试使用oncommand="sayHello('hello')"

Two suggestions:

  • you should encapsulate the code in a CDATA block.
  • try script type "application/x-javascript" instead of "text/javascript".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM