Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:33:00+00:00 2026-06-04T00:33:00+00:00

I am writing a Firefox extension using JavaScript and XUL. Part of my code

  • 0

I am writing a Firefox extension using JavaScript and XUL. Part of my code needs to be able to take some XUL markup and dynamically append it inside an existing container element. So basically I need to appendChild() but with a text string instead of a Node object. To do this, I tried the method listed in this question. Unfortunately this does not seem to work. It appears that div.childNodes returns an empty nodeList, which I can’t even append to the container. The error is

Error: Could not convert JavaScript argument arg 0 [nsIDOMXULElement.appendChild]

I’m not quite sure what I am doing wrong. Is there a way to make this work, or some alternate method to dynamically set the container’s markup?

Note: The container element is of type richlistbox.

    function updateContainerData(containerName){
      try{
        var resultsArray = DB.queryAsync("SELECT nodeData FROM waffleapps_privateurl");

        container = document.getElementById(containerName);

        for (var i = 0; i < resultsArray.length; i++) {

            /*
            // This works - appending an actual Node ( duplicate from a template)
            template = document.getElementById("list-item-template");
            dupNode = template.cloneNode(true);
            dupNode.setAttribute("hidden", false);
            container.appendChild(dupNode);
            */

            // This doesn't work
            div = document.createElement("div");
            //var s = '<li>text</li>';
var s = "<richlistitem id ='list-item-template'><hbox><checkbox label='' checked='true'/>  <description>DESCRIPTION</description><textbox>test</textbox><textbox></textbox></hbox></richlistitem>";

            div.innerHTML = s;
            var elements = div.childNodes;

            container.appendChild(elements); // error

        }
        }
        catch(err){
          alert( "Error: " + err.message);
        }
    }

I have gotten a bit further by using the following code. Now I am able to insert HTML elements in the container, but it appears that XUL elements are not parsed properly – the checkbox and textbox do not appear. I’m not sure how I would change this so it parses the HTML and XUL markup correctly.

    var s = "<richlistitem id ='list-item-template'><hbox><checkbox label='' checked='true'/>  <description>DESCRIPTION</description><textbox>test</textbox><textbox></textbox></hbox></richlistitem>";
    var dp = new DOMParser();
    container.appendChild(dp.parseFromString(s, "text/xml").documentElement);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:33:02+00:00Added an answer on June 4, 2026 at 12:33 am

    I finally figured out how to properly parse and append a XUL markup string. I was able to use the parseFromString method from a new DOMParser(). I had to make sure that the element’s markup specified the namespace (xmlns) so the parser knew it was XUL markup.

    The code below shows a full example.

    test.js:

    test = function(){
        alert("testing");
    
        container = document.getElementById("testing");
        var dp = new DOMParser();
    
        // must specify namespace
        var s = "<textbox xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' value='test' size='20'></textbox>";
    
        element = dp.parseFromString(s, "text/xml").documentElement;
    
        container.appendChild(element);
    
        document.getElementById("testing");
    }
    

    test.xul:

    <?xml version="1.0"?>
    
    <?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
    <?xml-stylesheet type="text/css"
      href="chrome://testextensionname/skin/test.css" ?>
    
    <!DOCTYPE window SYSTEM
      "chrome://testextensionname/locale/test.dtd">
    
    <window xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
            id="testWindow"
            orient="vertical" title="TEST" statictitle="TEST"
            width="50" height="50;" screenX="10" screenY="10"
           >
    <script type="application/x-javascript" src="chrome://testextensionname/content/test.js" />
    
    <hbox id="testing">
    <button label="Go" oncommand="test()"/>
    <textbox value='test' size='20'></textbox>
    </hbox>
    
    </window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am successfully writing to an Excel file, using javascript from my FireFox extension.
I'm writing a Firefox extension that needs to know what the username of the
I am writing my first FireFox extension and I have some questions. Maybe someone
I'm writing an extension for Firefox, and I need to log some data to
I'm writing a Firefox extension that needs to inject a css file into webpages.
I am writing a Firefox extension. I have setup an overlay for chrome://browser/content/browser.xul and
In the Firefox extension I'm writing, I have a variable containing some data that
I am writing a Firefox extension. I am using a content script that matches
I'm writing a firefox extension which displays a statusbarpanel containing some text. I want
I am writing a Firefox extension that needs to write and submit a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.