diff --git a/xpfe/global/resources/content/charsetOverlay.js b/xpfe/global/resources/content/charsetOverlay.js index 1530e0b3199..ef013217ace 100644 --- a/xpfe/global/resources/content/charsetOverlay.js +++ b/xpfe/global/resources/content/charsetOverlay.js @@ -44,20 +44,9 @@ function SelectDetector(event) function UpdateCurrentCharset() { - menu = Components.classes['component://netscape/rdf/datasource?name=charset-menu']; - - if (menu) { - menu = menu.getService(); - menu = menu.QueryInterface(Components.interfaces.nsICurrentCharsetListener); - } - - charset = document.commandDispatcher.focusedWindow.content.document.characterSet; + charset = document.commandDispatcher.focusedWindow.document.characterSet; charset = charset.toLowerCase(); - if (menu) { - menu.SetCurrentCharset(charset); - } - menuitem = document.getElementById('charset.' + charset); if (menuitem) { @@ -91,3 +80,27 @@ function UpdateMenus(event) UpdateCurrentCharset(); UpdateCharsetDetector(); } + +function charsetLoadListener (event) +{ + menu = Components.classes['component://netscape/rdf/datasource?name=charset-menu']; + + if (menu) { + menu = menu.getService(); + menu = menu.QueryInterface(Components.interfaces.nsICurrentCharsetListener); + } + + charset = window.content.document.characterSet; + charset = charset.toLowerCase(); + + if (menu) { + menu.SetCurrentCharset(charset); + } + + // XXX you know, here I could also set the checkmark, for the case when a + // doc finishes loading after the menu is already diplayed. But I get a + // weird assertion! +} + +contentArea = window.document.getElementById("appcontent") +contentArea.addEventListener("load", charsetLoadListener, true);