Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将xul编辑器与javascript一起使用?_Javascript_Xul - Fatal编程技术网

如何将xul编辑器与javascript一起使用?

如何将xul编辑器与javascript一起使用?,javascript,xul,Javascript,Xul,我想使用XUL的编辑器功能保存文档中的更改,并在加载时从中读取(我正在开发一个扩展) //NotePad.xul //NotePad.js 函数initEditor(){ var editor=document.getElementById(“myEditor”); editor.contentDocument.designMode='on'; } 我尝试将src属性更改为本地的html文档,但没有成功 所以我真正想做的是: 获取在编辑器中编写的文本(类似于.getAttribute('val

我想使用XUL的编辑器功能保存文档中的更改,并在加载时从中读取(我正在开发一个扩展)

//NotePad.xul
//NotePad.js
函数initEditor(){
var editor=document.getElementById(“myEditor”);
editor.contentDocument.designMode='on';
}
我尝试将
src
属性更改为本地的html文档,但没有成功

所以我真正想做的是:

  • 获取在编辑器中编写的文本(类似于
    .getAttribute('value')
    ,但我没有找到这样做的方法)

  • 从javascript写入它(类似于
    setAttribute('value')


  • 提前感谢,我真的被困在这里了。

    在我自己使用了大量代码使事情复杂化之后,我终于找到了它,老实说,这真是太愚蠢了,下面是如何完成的:

    要设置文本,请执行以下操作:

    var editor = content.document.getElementById("myEditor");
    editor.contentDocument.documentElement.innerHTML += "Whatever your text is";
    
    并获取文本很明显:

    editor.contentDocument.documentElement.innerHTML
    
    想到我花了很多时间在这件事上

    嗯,
    innerHTML
    各不相同,这取决于您给
    editortype
    的是html还是文本,因此如果editortype设置为text,那么我们应该使用innerText

    editor.contentDocument.documentElement.innerHTML