Search code examples
javascripthtmldoctypewindow.open

How to add DOCTYPE to new JavaScript-generated window?


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

How can i declare the <!DOCTYPE>?


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