Comment 465 for bug 263435

Revision history for this message
In , S-mocking (s-mocking) wrote :

There is an Unfocus add-on that seems to do this well, although right now it's implemented as a command line option. It's in JavaScript of course, but how about using the same underlying mechanism? Looking at the source (save xpi as zip and open components/cmd.js), this appears to be the code that actually does the unfocusing:

function unfocus() {
    var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                    .getService(Components.interfaces.nsIWindowMediator);
    var browserWindow = wm.getMostRecentWindow("navigator:browser");

    if(browserWindow.document.commandDispatcher.focusedElement)
        browserWindow.document.commandDispatcher.focusedElement.blur()

    browserWindow.focus();
    browserWindow.focus();
}