Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript open content type

In javascript I have a string, containing an SpreadsheetML file (excel xml)

I want to open a new window, and write this data to it, but have it open as excel.

Can I do that from javascript?

like image 309
CaffGeek Avatar asked Jul 19 '11 16:07

CaffGeek


People also ask

How do I find MIME type?

For detecting MIME-types, use the aptly named "mimetype" command. It has a number of options for formatting the output, it even has an option for backward compatibility to "file". But most of all, it accepts input not only as file, but also via stdin/pipe, so you can avoid temporary files when processing streams.

Is MIME type same as content-type?

content_type is an alias for mimetype. Historically, this parameter was only called mimetype, but since this is actually the value included in the HTTP Content-Type header, it can also include the character set encoding, which makes it more than just a MIME type specification.

What is MIME type in HTTP?

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.


1 Answers

Yes, you can do that with a data URL,. First, encode the document as base64. Then, use the following URL as source of your window:

var mtype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
var url = 'data:' + mtype + ';base64,' + base64data;
window.open(url);

This will require a modern browser.

like image 160
phihag Avatar answered Sep 23 '22 02:09

phihag