mike said:
Is there any way I can change the content type when I open a new window
other than opening a script in the open statement?
mywin =
window.open('','rpt','width=600,height=425,top=50,left=0,scrollbars=yes,toolbar=yes,resizable=yes,dependent=no');
Some browsers support data: URLs
(<
http://www.faqs.org/rfcs/rfc2397.html>) so you can try your luck with e.g.
var win = window.open(
'data:application/xhtml+xml,' + encodeURIComponent([
'<html xmlns="
http://www.w3.org/1999/xhtml">',
'<head>',
'<title>Example</title>',
'<script type="text/javascript">',
'window.onload = function (evt) {',
' alert(\'Content-Type: \' + document.contentType + ',
' \'; \' + document.documentElement.tagName);',
'}',
'</script>',
'</head>',
'<body>',
'<p>Kibology for all.</p>',
'</body>',
'</html>',
].join('\r\n')),
'jsTest'
);
With Mozilla 1.7 that shows the content type application/xhtml+xml and
the tag name as lower case 'html' so there the markup is indeed treated
as XHTML.
Opera 8.50 also seems to parse as XHTML, it does not expose a
contentType property to check that but the tag name is 'html in lower
case. Also when I try to pass in not well-formed stuff it gives an XML
parse error.
With a Firefox 1.5 beta nightly I can do
var win = window.open(
'data:image/svg+xml,' + encodeURIComponent([
'<svg xmlns="
http://www.w3.org/2000/svg">',
'<script type="text/javascript">',
'window.onload = function (evt) {',
' alert(\'Content-Type: \' + document.contentType + ',
' \'; \' + document.documentElement.tagName);',
'}',
'</script>',
'<circle cx="100" cy="100" r="20" fill="green" />',
'</svg>'
].join('\r\n')),
'jsTest'
);
as well and get the graphics rendered and the script shows the proper
values.
Opera 8.50 also renders the SVG graphics. Script in SVG is not supported
at all in that browser so the script in the SVG does not work there.
Keep in mind that I have never tested whether there are issues with
longer data URLs with long, complex markup.
mywin.document.write("Content-type:image/svg+xml");
In this example I would be changing the content type to svg.
In Netscape 4 you were supposed to do e.g.
mywin.document.open('image/svg+xml')
but other browsers have never supported that really. Mozilla 1.5 should
have some support for a limited set of content types e.g. you could do
mywin.document.open('text/plain')
but as far as I know there are no plans to support document.write for
stuff that would then go into an XML parser.
IE 6 seems to support open('text/plain') as well. Opera 8.50 does not
support that.
So document.write will probably not work for image/svg+xml, you could
start setting up a simple SVG document with a data: URL as shown above
and then it should be possible to add nodes using the DOM.