Home arrow XML arrow 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
(Page 1 of 6 )

A downloadable file for this article is available here.

The Edit menu is at this stage very basic, having just Copy, Paste and Cut actions to script.  As before, we are going to have to use XPCOM to enable this.  Compared to some of the previous functions we have used, the first one is relatively simple.  First, declare the function and get the editor element:

function copyToClip() {

  var editor = document.getElementById('mainContent');

In order to copy some text from the editor, some text will need to be selected and you will need to obtain whatever is selected:

var selected = editor.contentDocument.getSelection();

Once you have the selection, it is simple to copy this to the OS clipboard using the copy() method, but to do this, you need to get the interface that supports it, which is the nsIPlaintextEditor.  Once you have the interface, you can call the method and close the function:

editor = editor.getEditor(editor.contentWindow).QueryInterface


There’s no need to use the CI constant to save on code as only one interface is used in this operation.

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials