この記事の指示に従って、XULの要素を介してMidasを使用しようとしています。これまでのところ、以下のコードがあります。
<window id="main" title="Anunciador Blog Editor" width="300" height="300"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript">
<![CDATA[
var editor = null;
function onLoad() {
editor = document.getElementById('editor');
editor.contentDocument.designMode = 'on';
}
function onBoldButtonCommand() {
editor.contentDocument.execCommand('bold', false, null);
}
window.addEventListener("load", onLoad, false);
]]>
</script>
<button label="Bold" oncommand="onBoldButtonCommand();" />
<editor id="editor" type="content-primary" editortype="html" src="about:blank" flex="1" />
</window>
ただし、 でテキストを選択して [太字] ボタンをクリックすると<editor>
、テキストは変更されず、JS コンソールに次のエラーが表示されます。
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.execCommand]" nsresult: "0x80004005
(NS_ERROR_FAILURE)" location: "JS frame :: chrome://anunciador/content/main.xul ::
onBoldButtonCommand :: line 14" data: no]
次のように編集モードを有効にしているので、それは私には意味がありません。
editor.contentDocument.designMode = 'on';
また、行のみを変更すると
<editor id="editor" type="content-primary" editortype="html" src="about:blank" flex="1" />
に
<xhtml:iframe id="editor" src="about:blank"></xhtml:iframe>
iframe 内のテキストを編集および書式設定できます (ただし、エディターを使用することを本当に好みます)。
私は何かを忘れましたか?