Creating an XUL button gives a "component failure code",

I am one of the developers of TryAgain, a Firefox add-on that displays a custom error page when the site does not load. It essentially replaces Firefox netError.xhtmlwith an individual version.

To execute JavaScript from the extension code inside netError.xhtml, I added an XUL element <command>to the error page as follows:

var increment_btn = doc.
    createElementNS(
        "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
        "xul:command"
    );
increment_btn.setAttribute("id", "errorIncrement");
increment_btn.setAttribute("oncommand", "autoRetryThis();");
div.appendChild(increment_btn);

Whenever I need to execute autoRetryThis(), I just run doCommand()on the element. On my test machine, this works fine under Firefox 2.0 to 4.0b10. I received the following problem report :

Error: component return code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMHTMLDocument.createElementNS]

The error indicates the first line of the above code.

, createElementNS(), .

0
2

XUL . , , XUL XHTML XML.

XHTML <button> onclick() , :

try {
    var evt = doc.createEvent('HTMLEvents');
    evt.initEvent('click', false, false);
    btn.dispatchEvent(evt);
} catch (e) {
    btn.click();
}

btn.click() ? , . .

0

xul: name createElementNS.

+1

Source: https://habr.com/ru/post/1764457/


All Articles