Why can't I access the contentWindow of an iframe?! I am trying to create something like https://jsbin.com with it's functionality, but I am unable to access the contentWindow of the iframe for me to run my js in it. I can use eval to run my javascript string... But I'm unable to run it inside the iframe, therefore I suspect I am unable to access the contentWindow of the iframe. Please enlighten me, Thank you in advance. Here is my code:
<html>
<head>
<title>JS Bin Clone</title>
</head>
<body>
<div id="javascript" class="code-container">
<textarea name="javascript" id="javascriptTextArea"></textarea>
</div>
<div id="output" class="code-container">
<iframe id="output-iframe"></iframe>
</div>
<script type='text/javascript'>
function updateOutput() {
var js = document.getElementById('javascriptTextArea').value;
document.getElementById('output-iframe').contentWindow.eval(js);
}
updateOutput();
</script>
</body>
</html>
PS: (I am using eval()).