Open Win - Content Type

M

mike

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');

mywin.document.write("Content-type:image/svg+xml");

In this example I would be changing the content type to svg.

I tried this and it did not work.

The window gets opened up as html.

Any help is appreciated.

Mike
 
M

Martin Honnen

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.
 
M

Martin Honnen

mike said:
I tried that in IE and it barfed all over me.

The only thing that I suggested that works with IE 6 is
var win = window.open('', 'windowName');
win.document.open('text/plain');
win.document.write('Line1\r\nLine2');
win.document.close();
If you tried data: URLs with IE then sorry, I said some browsers support
data: URLs, as far as I know IE/Win does not support them at all (e.g.
not even statically in an HTML document with <img
src="data:image/gif,...">) so hoping that doing window.open with a data:
URL in IE/Win works is not fruitful.
In my understanding if you want to have content type like image/svg+xml
rendered that IE does not handle itself but which are handled by plugins
then you need to have a file: or http: or ftp: URL, there is no way to
have script pump in data into a window with document.write which is then
handled by a plugin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top