Akinohana
Akinohana

Reputation: 35

How to Debug a JavaScript code when it is loaded by document.write?

I can see the code in Element view in Chrome, but not in source because it is load by document.write function.

How do I set a breakpoint in this case?

Upvotes: 1

Views: 324

Answers (1)

Gustavo Jantsch
Gustavo Jantsch

Reputation: 381

I suppose you have access to the source code that generates the document.write, you can add a call to the 'debugger' like this:

<script>
document.write('<sc' + 'ript> debugger; alert(0);</s' + 'cript>');
</script>

I you have the debugger opened on chrome, it will stop the execution and show the generated code on the Sources tab.

Upvotes: 2

Related Questions