12

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.

bruntime
  • 371
  • 2
  • 12
Nishantha
  • 4,665
  • 5
  • 29
  • 47

5 Answers5

11

Here's one alternative: http://jsfiddle.net/skibulk/erh7m9og/1/

document.write = function (str) {
    document.body.insertAdjacentHTML("beforeend", str);
}

document.write("¡hola mundo");
skibulk
  • 2,768
  • 30
  • 39
8

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

Why is document.write considered a "bad practice"?

Community
  • 1
  • 1
Mithun Satheesh
  • 25,056
  • 14
  • 73
  • 97
4

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

Isaac
  • 10,133
  • 5
  • 27
  • 43
0

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

CuriousMind
  • 31,669
  • 24
  • 84
  • 127
0

You can try using document.body.innerHtml = "Hello";

Pavlito
  • 99
  • 1
  • 1
  • 7