I'm opening new page using JS and writing into it the HTML code, however when I try to write JS inside the new page using document.write()
function it doesn't work. Apparently the main JS closes as soon as the it sees </script>
which is intended for the JS of the new page that will be opened.
Is there away around this?
var opened = window.open("");
opened.document.write("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">");
opened.document.write("<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">");
opened.document.write("<head><title>Print Copy</title></head>");
opened.document.write("<body>");
opened.document.write("<script type="text/javascript">");
opened.document.write("</script>");
opened.document.write("<p>test</p></body></html>");
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…