简体   繁体   中英

How to evaluate code in ace editor

I am trying to get html code from ace editor and show preview in iframe .

Example: Code Academy

Here is what i have been trying:

var textarea = $('textarea[name="html"]');
var view=$('#view');
textarea.hide();
var editor = ace.edit("editor");
editor.setTheme("ace/theme/eclipse");
editor.getSession().setMode("ace/mode/html");
editor.getSession().on('change', function () {
    var preview = view.eval(editor.getSession().getValue());
});
setTimeout(preview, 300);

Try this:

var textarea = $('textarea[name="html"]');
var view=$('#view');
textarea.hide();
var editor = ace.edit("editor");
editor.setTheme("ace/theme/eclipse");
editor.getSession().setMode("ace/mode/html");
editor.getSession().on('change', function () {
    view.contents().find('body').html(editor.getSession().getValue());
});

I presumed view is your iframe .

I am using the contents() jQuery function to get into the iframe and replace the html with what is in the editor.

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