Search code examples
javascriptfirefoxxpcomhtml-encode

How to HTML encode a string in JavaScript from a Firefox extension


So I know I can write my own HTML-encoding function like this:

function getHTMLEncode(t) {
    return t.toString().replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}

But I was wondering if there were any native facility for this that is available to XPCOM components. I'm writing a component, not an overlay, so I don't have a DOM around to do tricks like creating a DOM element and setting its innerHTML.


Solution

  • The answer appears to be no - there is no built in function in Firefox to HTML-encode a string from an XPCOM component.