我正在使用 JS 打开新页面并将 HTML 代码写入其中,但是当我尝试使用document.write()
函数在新页面中编写 JS 时它不起作用。显然,主 JS 在看到</script>
用于将要打开的新页面的 JS 时立即关闭。
有没有解决的办法?
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>");