Question

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

How can i declare the <!DOCTYPE>?

Was it helpful?

Solution

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();
} 

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top