Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find and replace text in CKEditor using Javascript?

How could I find and replace text in CKEditor using Javascript? Thanks for your suggestion!

like image 848
Thurein Avatar asked Apr 12 '11 12:04

Thurein


1 Answers

try this

editor = CKEDITOR.instances.fck; //fck is just my instance name you will need to replace that with yours

var edata = editor.getData();

var replaced_text = edata.replace("idontwant", "iwant this instead"); // you could also use a regex in the replace 

editor.setData(replaced_text);

you may want to put that in a blur event or soemthing

like image 195
mcgrailm Avatar answered Oct 17 '22 08:10

mcgrailm