I have the following code below in which I am using to attempt to dynamically write some javascript into a new html page at the click of a button.
I am however getting an error when attempting to do so I get “unterminated string constamnt”
in theory, this should work:
var html = '<!DOCTYPE html>\n'
html += '<html>\n'
html += '<head>\n'
html += '<script type="text/javascript">\n'
html += 'function testme() {\n'
html += 'alert("the test worked!")\n'
html += '}\n'
html += '</script>\n'
html += '</head>\n'
html += '<body>\n'
html += '</body>\n'
html += '</html\n'
window.open('','').document.write(html)
You are missing a closing > on the last line
should be
If the code is inline and not in an external script, you will need to break up the closing script tag.
also, use semicolons.
Now the window.open, document.write line looks strange. Most developers would write it as