Try It Yourself Editor Js
Solution 2:
JavaScript inserted via innerHTML
will not be executed due to security reasons:
HTML5 specifies that a
<script>
tag inserted via innerHTML should not execute.
from MDN: Element.innerHTML - Security considerations, see also: W3: The applied innerHTML algorithm.
A possible solution using the jQuery method .append()
works around that, as it somehow evals the content. But this will still not solve your problem, as the JavaScript code is executed in the current scope.
Here's a test scenario:
functionupdate() {
var codeinput = document.getElementById('codebox').value;
$(window.frames[0].document.body).append(codeinput);
}
Try to insert this script:
<script>alert( document.getElementById('tryitcontainer') );
</script>
and this one:
<pid="test">Test</p><script>window.frames[0].document.getElementById('test').innerHTML = 'updated';
</script>
The first one will return a [object HTMLDivElement]
or similar. Here you can see, that you're still in the same scope as the parent frame. The second one will correctly update the content within the iframe. Keep that in mind, when experimenting with those things.
Maybe Executing elements inserted with .innerHTML has some more infos for you.
Post a Comment for "Try It Yourself Editor Js"