I have this jsfiddle where i load inside an iframe an http url. After i want to delete the content and replace it with html code i create with javascript. This alternate will happen many times. When i try with the following code i get this error Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://fiddle.jshell.net" from accessing a frame with origin "https://jsfiddle.net". Protocols, domains, and ports must match.
HTML
<iframe id = "Preview" src ="https://jsfiddle.net/"></iframe>
<button onclick = "changeSRCtoLocal()">Click me</button>
<br>
<span>click at the button to change html content of iframe</span>
JS
function changeSRCtoLocal(){
document.getElementById('Preview').src = "about:blank";
var iframe = document.getElementById('Preview'),
iframedoc = iframe.contentDocument || iframe.contentWindow.document;
iframedoc.body.innerHTML = "<html>How can someone view me?</html>";
alert()
}
UPDATE
To any answers that say that you can't do it please explain why this exaple works??