2

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

How can i declare the <!DOCTYPE>?

Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
user2452518
  • 23
  • 1
  • 3
  • document.doctype but DocumentType objects cannot be created dynamically in DOM Level 1; – Givi Jun 04 '13 at 16:14

2 Answers2

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();
} 
bastos.sergio
  • 6,684
  • 4
  • 26
  • 36
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

Community
  • 1
  • 1
Mike McCoy
  • 797
  • 2
  • 10
  • 19