Browse by Month RSS Feed
  • September 2010
  • August 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010

  • XUL: innerHTML()July 16, 2009
    Filed under: Code, JavaScript, Life, XUL @ 12:44 pm

    While I'm on a XUL bint... here's how to implement innerHTML in XUL. Invaluable for debugging:

    Object.prototype.xulInnerHTML = function()
    {
      return (new XMLSerializer()).serializeToString(this);
    };

    Usage:

    var myElement = document.getElementById("myID");
    alert(myElement.xulInnerHTML);

    EDIT: I've since learned that extending the built-into JS objects in this manner is NOT recommended. Instead you should implement this function as a procedural function instead. Just a heads up.

    Comments (0)


    Filed under: Code, JavaScript, XUL @ 12:19 pm

    XUL is fun, but DAMN there's not enough doc out there. Coming up with this function took far longer than it should! Other functions I found on the web didn't work for my case.

    var g = {};
    g.removeSelectedTreeRows = function(treeID)
    {
        var tree = document.getElementById(treeID);
        var rangeCount = tree.view.selection.getRangeCount();
        var start = {};
        var end   = {};
        for (var i=0; i<rangeCount; i++) 
        { 
            tree.view.selection.getRangeAt(i, start, end);
            for (var c=end.value; c>=start.value; c--) 
            {
                tree.view.getItemAtIndex(c).parentNode.removeChild(tree.view.getItemAtIndex(c));
            }
        }
    };

    Comments (0)