admin管理员组

文章数量:1331648

I try to get and set the value of an ace editor on a random website. But I do not know the instance names. Also there is no ID on any div. Is there a way to find one or all instances, so that I can access the api like:

var editor = ace.edit("...");

Thanks for your advice :)

I try to get and set the value of an ace editor on a random website. But I do not know the instance names. Also there is no ID on any div. Is there a way to find one or all instances, so that I can access the api like:

var editor = ace.edit("...");

Thanks for your advice :)

Share Improve this question asked Sep 14, 2015 at 13:40 pa1ndpa1nd 4424 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

all ace editors need to have ace_editor classname and ace.edit saves editor to <domNode>.env.editor so the following should work in most cases

var all = document.querySelectorAll(".ace_editor");
for (var i = 0; i < all.length; i++) {
    if (all[i].env && all[i].env.editor)
        console.log(all[i].env.editor)
    else
        console.log("can't get editor from" all[i])
}

This won't work for editors created as new Editor() which do not have envand for editors created in shadow dom, which can't be found via querySelectorAll.

本文标签: javascriptAce EditorHow to find one or all instancesStack Overflow