开发者

How to programatically select all text inside a TinyMCE editor

开发者 https://www.devze.com 2022-12-28 14:32 出处:网络
I\'m looking for a way to programatically select all the content inside a TinyMCE editor instance. The reason I need this is that I\'d like it if all the text inside the editor was selected, as soon

I'm looking for a way to programatically select all the content inside a TinyMCE editor instance.

The reason I need this is that I'd like it if all the text inside the editor was selected, as soon as someone clicks on it (I'm using TinyMCE in conjunction with JEditable, by the way).

Than开发者_如何学运维ks,

Edan


Assuming you have your TinyMCE editor instance stored in a variable called ed:

ed.selection.select(ed.getBody(), true);


For tinyMCE 4 I'm using the Range Object for selection:

function selectAll(editor) {
    range = editor.dom.createRng();
    range.selectNodeContents(editor.getBody());
    editor.selection.setRng(range);
}

selectAll(tinyMCE.focusedEditor);
0

精彩评论

暂无评论...
验证码 换一张
取 消