Home arrow XML arrow Page 6 - Back to XUL: Completing the JavaScript Logic

Back to XUL: Completing the JavaScript Logic

The previous article saw us complete the File menu, making use of XPCOM to handle some of the more complex behaviors. This article will go on to discuss adding behavior to the two remaining menus, the Edit and Help menus.

Author Info:
By: Dan Wellman
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
February 13, 2006
  1. · Back to XUL: Completing the JavaScript Logic
  2. · Defining a Function
  3. · The Help Menu
  4. · The About Window
  5. · Making the Toolbar Work
  6. · Finishing up the Functions

print this article

Back to XUL: Completing the JavaScript Logic - Finishing up the Functions
(Page 6 of 6 )

As you can see it isnít as good as standard parameter passing, in which case any value can be used as a parameter, but it works in its own quirky kind of way and saves some code (somewhere) too.  Add the code for the other two insert functions:

function insert2(str) {

  var str1 = '<radiogroup>  <radio id="" label=""/>  </radiogroup>';
  var str2 = '<window id="" title="" height="" width="" xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul"/>  </window>';
  var str3 = '<wizard id="" title="" xmlns="http://www.mozilla.org/keymaster/gatekeeper/
there.is.only.xul">  <wizardpage>  </wizardpage>  </wizard>';
  var str4 = '<editor id="" editortype="" type="" src=""/>';
  var str5 = '<browser id="" homepage="" type=""/>';
  var str6 = '<iframe id="" src=""/>';

  var editor = document.getElementById('mainContent');
  editor = editor.getEditor(editor.contentWindow).QueryInterface

  if (str == menubar) {
  } else if (str == toolbar) {
  } else if (str == directories) {
  } else if (str == locationbar) {
  } else if (str == statusbar) {
  } else if (str == scrollbars) {


function insert3(str) {

  var str1 = '<titlebar id=""/>'

  var editor = document.getElementById('mainContent');
  editor = editor.getEditor(editor.contentWindow).QueryInterface

  if (str == menubar) {


The last curly brace above sees the end of the code required in the JavaScript file, but you still need to add calls to the insert() function to each of the menuitems, passing in one of the BarProp parameters, for example:

<menuitem id="buttonMenubar" label="&menubarLabel;"

With both the XUL and JS files saved, your application (version 1 at least) is complete.  Now, itís still a little buggy in places; the new file command (where we set the src of the editor to about:blank) only seems to work once for example.  Overall however, I donít think this is too much of a problem; look at the number of bugs in a Windows OS release!

This also now sees the end of this series on creating an application with XUL.  I hope youíve followed along with the tutorial and I hope that you havenít had too many difficulties getting it to work.  If this has just got your appetite for XUL going, please continue to build, adapt and refine the application; you can extend the program in any way you can think of by simply adding elements to the XUL file and functions to the script file and are limited only by the bounds of your imagination.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials