简体   繁体   中英

How to use xul editor with javascript?

I want to use the editor feature of XUL to save changes in a document and read from it on load (I am developing an extension)

//NotePad.xul
<editor id="edit" type="content" editortype="html" src="about:blank" flex="1"/>

//NotePad.js
function initEditor(){
var editor = document.getElementById("myEditor");
editor.contentDocument.designMode = 'on';
}

I tried Changing the src attribute to an html doc i have locally but it didnt work.

So what i actually wanna do is :

  1. Get the text written in the editor (something like .getAttribute('value') , but i didnt find a way to do so)

  2. Write to it from javascript (something like setAttribute('value') )

Thanks in advance, i am really stuck in here.

After Complicating things myself using a lot of code i finally found it, and it is really dumb to be honest, well here is how it gets done :

to set text :

var editor = content.document.getElementById("myEditor");
editor.contentDocument.documentElement.innerHTML += "Whatever your text is";

and get text it is obvious :

editor.contentDocument.documentElement.innerHTML

to think that i spent a loooot of time in this is ...

well the innerHTML varies, it depends on what you gave to editortype either html or text, so in case the editortype is set to text in that case we should use innerText.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM