When I try to run one of my JavaScript files on JSFiddle, I get the following error message:
document.write is disallowed in JSFiddle environment and might break your fiddle.
How do I fix this issue?
Note: When I use external resources, it works fine. But I want to use the JavaScript panel for scripts.
Here's one alternative: http://jsfiddle.net/skibulk/erh7m9og/1/
document.write = function (str) {
document.body.insertAdjacentHTML("beforeend", str);
}
document.write("¡hola mundo");
its not any issue with your code. Its related to jsfiddle that it doesnt allow to run those code having document.write
.
As an alternative you could use
console.log(x);
where ever you are having a
document.write(x);
and check up in the chrome inspector or firebug console for verifying result.
If you are more concerned about why document.write
is blocked by jsfiddle, the below So posts may help to get a better understanding.
Why am i receiving this jsfiddle error, document.write can be a form of eval
While testing the script, you could do this:
document.write = function(txt)
{
console.log(txt);
}
document.write("hey");
And when you are satisfied, just take that part out
You have document.write
in your code, this breaks the result panel and the initialization of awesome.
Remove document.write
from your code & it start working again
You can try using
document.body.innerHtml = "Hello";
来源:https://stackoverflow.com/questions/16783834/error-message-document-write-is-disallowed-in-jsfiddle