简体   繁体   中英

how to set the value of textarea with toolbar using javascript?

I'm trying (from my firefox extension) to set the value of a textarea with toolbar which placed when creating a blog before posting it like in blogger or live-journal.

In simple textarea I can get or set the textarea value by:

var myTextArea = gBrowser.contentDocument.getElementsByTagName("textarea")[0];
alert(myTextArea.value); // alerts the old value
myTextArea.value = "this is the new value of the textarea"; 

where there of course was only one textarea.

The problem is in textarea with toolbar. I succeeded changing the value of the textarea i'm writing in right now even though it has toolbar, but in all other sites especially blog sites the element value is changed but the text in the page stays the same.

I thought maybe the textarea is CKEditor but I don't know it's name so I can't use:

FCKeditorAPI.GetInstance('InstanceName').insertText("new value in textarea");

is the textarea in sites such as mentioned above is CKEditor? and more important - how do i set the it's value?

thanks!

I believe you can do:

for(x in CKEDITOR.instances) {
  CKEDITOR.instances[x].insertText("new value in textarea");
}

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