I am doing a web editor, with a textarea that recives the user code and an iframe that shows in real time the html. I have an event that listen on keyup users , this is the code i use to execute javascript on iframe
var iframe = $("#iframeresults").contents()
$("#wrapper").on("paste keyup", function(){
setTimeout(function(){
iframe.find("body").html(webEditor.getHtml());
iframe.find("style").html(webEditor.getCss());
iframe.find("script").remove()
var script = document.createElement("script")
script.text = webEditor.getJS()
iframe.find("head")[0].appendChild(script)
},800)
});
This works fine but i have to remove and create the script tag every time the user press a key, my question is , is there another way to do this without touching the dom?
I tried this link
But if i use eval and the code contains sintax erros, this stops