Forum Moderators: open

Message Too Old, No Replies

Doing "content-type" properly with javascript

trying to do export to csv

         

Replicon

7:22 pm on Dec 7, 2004 (gmt 0)

10+ Year Member



Hi,

I'm trying to do a dynamic popup window with cvs data that'll automatically have msexcel open (or better yet, ask you to save or open) some csv data using javascript.

...something along the lines of:


function clicky() {
var pop1 = open("", "win1", "width=400 height=400 ");
var doc = pop1.document.open("application/msexcel");
doc.writeln("cow,12,moo");
doc.writeln("dog,20,arf");
doc.writeln("cat,41,meow");
doc.close();
pop1.focus();
}

is this doable in js? If I replace "application/msexcel" with "text/plain", it seems to work (that is, puts in the line breaks, so we know it's not parsing html anymore), but when trying to have it export to excel, it doesn't seem to be very happy. What am I missing?

Bonus points if it also works in Firefox! (seems that only IE recognized the "text/plain" in my previous experiment).

Thanks!

p.s. gah! why won't this thing let me do proper 4-space indentation? :)

Replicon

10:17 pm on Dec 7, 2004 (gmt 0)

10+ Year Member



Sorry, I meant CSV data (comma-separated values)

Bernard Marx

10:30 pm on Dec 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I really don't think this is possible in Javascript like this
(ie without invoking ActiveX).

The "text/plain" argument will only work with IE. It's useful sometimes, but it's the best you'll get.

Bernard Marx

12:11 am on Dec 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems that some disagree:
[devguru.com...]
[javascriptkit.com...]

But then MS says:

"text/html" Default. Currently the only MIME type supported for this method.

..which isn't true either, as you already know.