2

I'm generating new a window with JavaScript using window.open and putting some content in it.

How can i declare the <!DOCTYPE>?

1
  • document.doctype but DocumentType objects cannot be created dynamically in DOM Level 1;
    – Givi
    Jun 4, 2013 at 16:14

2 Answers 2

1

It's not possible.

window.open just opens a new browser instance. It's the page's responsability, inside the popup, to declare its doctype.

Edit

Actually, I found this, but this example will only work if you're planning on overwriting the content of the newly opened window.

function openWin(){
    var winTitle='blah';
    var winBg='#FF0000';
    var newWin=window.open('', '', 'height=130, width=160');
    newWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+winTitle+'</title></head>');
    newWin.document.write('<body bgColor="'+winBg+'"><img src="images/picture.jpg" border=0></body></html>');
    newWin.document.close();
} 
0

I don't think you can use window.open alone for this but it seems you can do this with a little more coding.

Check out this similar question. I think you could easily adapt it to do what you're asking.

Add Content to new open window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.