At the bottom of my HTML page I have declared a div with the text of a JavaScript function.
<div style="display:none" id="newwinner">
function newwin()
{ nwin = window.open("","_blank", "scrollbars,menubar,toolbar, status,resizable,location");
content = document.body.innerHTML;
if(nwin != null)
{ nwin.document.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /></head><body>"+content+"</body></html>");
nwin.document.close();
}
}
</div>
Now I want to insert that somewhere else. This gets the JavaScript code:
nw = document.getElementById("newwinner");
var g = document.createElement("script");
g.text = nw.innerHTML;
var tab = document.getElementById("Maintable");
tab.insertBefore(g, tab.childNodes[0]);
I always get the same error:
Uncaught SyntaxError: missing ) after argument list
The problem is the second level of quotes, like 'Content-Type'
. It looks like the single quotes are converted to double quotes here. That is what I see both in the Chrome console and when I do an alert()
.
I tried many variations, escaping with backslashes, using escaped double quotes, using "
, but none of them solved the problem. What can I do to solve this?
Note that this is specific for a script node. When I use a DIV instead it works.