By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Open Win - Content Type

P: n/a
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,de pendent=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

Sep 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


mike wrote:
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,de pendent=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.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 27 '05 #2

P: n/a
Thanks Martin, very useful ....

Sep 27 '05 #3

P: n/a
Martin,

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

Mike

Sep 27 '05 #4

P: n/a


mike wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 28 '05 #5

P: n/a
Martin, Thanks again, Mike

Sep 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.