Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?

Reply
Thread Tools

FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?

 
 
FAQ server
Guest
Posts: n/a
 
      05-11-2007
-----------------------------------------------------------------------
FAQ Topic - How do I prompt a "Save As" dialog for an
accepted mime type?
-----------------------------------------------------------------------

It is not possible with client-side JavaScript.

Some browsers accept the Content-Disposition header, but this
must be added by the server. Taking the form:-
` Content-Disposition: attachment; filename=filename.ext `

http://aspfaq.com/show.asp?id=2161

http://support.microsoft.com/support.../Q260/5/19.ASP


===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-12-2007
FAQ server wrote on 12 mei 2007 in comp.lang.javascript:

> -----------------------------------------------------------------------
> FAQ Topic - How do I prompt a "Save As" dialog for an
> accepted mime type?
> -----------------------------------------------------------------------
>
> It is not possible with client-side JavaScript.


Which is logical, my dear Watson Faq, as the below header line ASP-
insertion is "executed" in the browser BEFORE any clientside code runs.

From a clientside only webside point of view,
a view held by many clientside javascript programmers out of necessity,
the question realy is:

Is there anything in a clickable anchor, that forces such user response?

There is!

<a href='x.html'
onclick='alert("please rightclick, choose `save as...`");return false;'
>download me</a>


==================

> Some browsers accept the Content-Disposition header, but this
> must be added by the server. Taking the form:-
> ` Content-Disposition: attachment; filename=filename.ext `


<script language='jscript' runat='server'> //ASP-enabled server needed
Response.AddHeader('content-disposition','attachment;filename=x.html');
</script>

> http://aspfaq.com/show.asp?id=2161


[shows only ASP-vbscript]

>
> http://support.microsoft.com/support.../Q260/5/19.ASP



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
shimmyshack
Guest
Posts: n/a
 
      05-12-2007
On May 12, 9:07 am, "Evertjan." <(E-Mail Removed)> wrote:
> FAQ server wrote on 12 mei 2007 in comp.lang.javascript:
>
> > -----------------------------------------------------------------------
> > FAQ Topic - How do I prompt a "Save As" dialog for an
> > accepted mime type?
> > -----------------------------------------------------------------------

>
> > It is not possible with client-side JavaScript.

>
> Which is logical, my dear Watson Faq, as the below header line ASP-
> insertion is "executed" in the browser BEFORE any clientside code runs.
>
> From a clientside only webside point of view,
> a view held by many clientside javascript programmers out of necessity,
> the question realy is:
>
> Is there anything in a clickable anchor, that forces such user response?
>
> There is!
>
> <a href='x.html'
> onclick='alert("please rightclick, choose `save as...`");return false;'
>
> >download me</a>

>
> ==================
>
> > Some browsers accept the Content-Disposition header, but this
> > must be added by the server. Taking the form:-
> > ` Content-Disposition: attachment; filename=filename.ext `

>
> <script language='jscript' runat='server'> //ASP-enabled server needed
> Response.AddHeader('content-disposition','attachment;filename=x.html');
> </script>
>
> >http://aspfaq.com/show.asp?id=2161

>
> [shows only ASP-vbscript]
>
>
>
> >http://support.microsoft.com/support.../Q260/5/19.ASP

>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)


<html>
<head></head>
<body>
<iframe frameborder="0" width="0" height="0" src="" id="file"
name="file"></iframe>
<a href="data:application/vnd.ms-excel;base64,MSwyLDMsNA=="
target="file">click here</a>
</body>
</html>

 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      05-12-2007
shimmyshack wrote:
> <html>
> <head></head>
> <body>
> <iframe frameborder="0" width="0" height="0" src="" id="file"
> name="file"></iframe>
> <a href="data:application/vnd.ms-excel;base64,MSwyLDMsNA=="
> target="file">click here</a>
> </body>
> </html>


I find it odd that only Opera gets it right.

Isn't this type of thing useless for all MIME types that the browser can
open natively?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
 
Reply With Quote
 
shimmyshack
Guest
Posts: n/a
 
      05-12-2007
On May 12, 12:13 pm, -Lost <(E-Mail Removed)> wrote:
> shimmyshack wrote:
> > <html>
> > <head></head>
> > <body>
> > <iframe frameborder="0" width="0" height="0" src="" id="file"
> > name="file"></iframe>
> > <a href="data:application/vnd.ms-excel;base64,MSwyLDMsNA=="
> > target="file">click here</a>
> > </body>
> > </html>

>
> I find it odd that only Opera gets it right.
>
> Isn't this type of thing useless for all MIME types that the browser can
> open natively?
>
> --
> -Lost
> Remove the extra words to reply by e-mail. Don't e-mail me. I am
> kidding. No I am not.


yes you are right.
but what if you dont set the correct mimetype for the file,
I haven't pushed at the edges on this one.

<html>
<body>
<iframe frameborder="0" width="100" height="100" src="" id="file"
name="file"></iframe>
<?php
$data = file_get_contents( 'http://groups.google.com/groups/img/gicons/
science_n_technology_42.gif' );
#$mime = 'image/gif'; #true mimetype
$mime = 'application/x-unknown'; #arbitrary one
?>
<a href="data:data:<?php echo $mime; ?>;base64,<?php echo
base64_encode($data);?>" target="file">click here</a>
</body>
</html>

The filename is the tough part, it's argueable whether a "save as"
dialog _is_ prompted for an accepted mime because we are setting an
unacceptable mime, for data which after all doesnt have an intrisic
mime. I just thought this was worth a mention, a curiosity for mozilla
based browsers, one wonders if it's a feature that might be removed
later - if it is never adopted by IE.

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      05-12-2007
shimmyshack a écrit :
>
> <html>
> <head></head>
> <body>
> <iframe frameborder="0" width="0" height="0" src="" id="file"
> name="file"></iframe>
> <a href="data:application/vnd.ms-excel;base64,MSwyLDMsNA=="
> target="file">click here</a>
> </body>
> </html>


Funny, on my Mac with FF in local, that opens Excel with in 1st cell
'1,2,3,4'
(after a dialog to 'open' or 'save' or 'cancel')
and ... nothing comes in the iframe.

the name of the sheat is : 5zfcwiy0-1.xls
- from where this name comes ?
- from where '1,2,3,4' comes ?

Where to find some more informations about this
href="data:application/vnd.ms-excel;base64,..." ?

Can we use it with other applications !MS ?
application/openoffice.org;
application/another-application;

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
shimmyshack
Guest
Posts: n/a
 
      05-12-2007
On May 12, 2:16 pm, ASM <(E-Mail Removed)>
wrote:
> shimmyshack a écrit :
>
>
>
> > <html>
> > <head></head>
> > <body>
> > <iframe frameborder="0" width="0" height="0" src="" id="file"
> > name="file"></iframe>
> > <a href="data:application/vnd.ms-excel;base64,MSwyLDMsNA=="
> > target="file">click here</a>
> > </body>
> > </html>

>
> Funny, on my Mac with FF in local, that opens Excel with in 1st cell
> '1,2,3,4'
> (after a dialog to 'open' or 'save' or 'cancel')
> and ... nothing comes in the iframe.
>
> the name of the sheat is : 5zfcwiy0-1.xls
> - from where this name comes ?
> - from where '1,2,3,4' comes ?
>
> Where to find some more informations about this
> href="data:application/vnd.ms-excel;base64,..." ?
>
> Can we use it with other applications !MS ?
> application/openoffice.org;
> application/another-application;
>
> --
> Stephane Moriaux et son (moins) vieux Mac déjà dépassé
> Stephane Moriaux and his (less) old Mac already out of date


i've seen it used in ajax apps a bit, for small images, not sure why,
perhaps just because they could.

its not M$ compaitible - they never implemented this.
the name is randomly generated by your OS, and the source
MSwyLDMsNA==
is 1,2,3,4 base64 encoded
here's a start:
http://www.ietf.org/rfc/rfc2397.txt
and you could use it with whatever application deals with the mimetype
you specify in the source.

cool huh, but limited in scope

 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      05-12-2007
shimmyshack a écrit :
>
> <html>
> <body>
> <iframe frameborder="0" width="100" height="100" src="" id="file"
> name="file"></iframe>
> <?php
> $data = file_get_contents( 'http://groups.google.com/groups/img/gicons/
> science_n_technology_42.gif' );


How, with JS, could I get content of my image file ?
(gif image on same domain)

> #$mime = 'image/gif'; #true mimetype
> $mime = 'application/x-unknown'; #arbitrary one
> ?>
> <a href="data:data:<?php echo $mime; ?>;base64,<?php echo
> base64_encode($data);?>" target="file">click here</a>


is it : href="data:data: ... "
or : href="data: ... "
?


> </body>
> </html>
>
> The filename is the tough part, it's argueable whether a "save as"
> dialog _is_ prompted for an accepted mime because we are setting an
> unacceptable mime, for data which after all doesnt have an intrisic
> mime. I just thought this was worth a mention, a curiosity for mozilla
> based browsers, one wonders if it's a feature that might be removed
> later - if it is never adopted by IE.


Tried with FF followed code (*) :

onclick="parent.myfile.location.href='data:image/gif;base64,'+
encodeBase64(document.images[0].src); return false;"

but the iframe tells :
picture “data:image/gif;base64,blah”
can't be dispayed because of errors.

Think 'data' is the image's url (encoded in base 64)


(*) encodeBase64() is a JS encoding function found here :
<http://www.ioswebdesign.com/index.php/2006/12/06/>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
 
Reply With Quote
 
shimmyshack
Guest
Posts: n/a
 
      05-12-2007
On May 12, 2:52 pm, ASM <(E-Mail Removed)>
wrote:
> shimmyshack a écrit :
>
>
>
> > <html>
> > <body>
> > <iframe frameborder="0" width="100" height="100" src="" id="file"
> > name="file"></iframe>
> > <?php
> > $data = file_get_contents( 'http://groups.google.com/groups/img/gicons/
> > science_n_technology_42.gif' );

>
> How, with JS, could I get content of my image file ?
> (gif image on same domain)
>
> > #$mime = 'image/gif'; #true mimetype
> > $mime = 'application/x-unknown'; #arbitrary one
> > ?>
> > <a href="data:data:<?php echo $mime; ?>;base64,<?php echo
> > base64_encode($data);?>" target="file">click here</a>

>
> is it : href="data:data: ... "
> or : href="data: ... "
> ?
>
> > </body>
> > </html>

>
> > The filename is the tough part, it's argueable whether a "save as"
> > dialog _is_ prompted for an accepted mime because we are setting an
> > unacceptable mime, for data which after all doesnt have an intrisic
> > mime. I just thought this was worth a mention, a curiosity for mozilla
> > based browsers, one wonders if it's a feature that might be removed
> > later - if it is never adopted by IE.

>
> Tried with FF followed code (*) :
>
> onclick="parent.myfile.location.href='data:image/gif;base64,'+
> encodeBase64(document.images[0].src); return false;"
>
> but the iframe tells :
> picture "data:image/gif;base64,blah"
> can't be dispayed because of errors.
>
> Think 'data' is the image's url (encoded in base 64)
>
> (*) encodeBase64() is a JS encoding function found here :
> <http://www.ioswebdesign.com/index.php/2006/12/06/>
>
> --
> Stephane Moriaux et son (moins) vieux Mac déjà dépassé
> Stephane Moriaux and his (less) old Mac already out of date


I think it's the binary data.
What you would do is have an XHR call return base64 encoded data from
a serverside script, the string would then not have errors. Depending
on the browser, there might be a limit to the size of the image, this
method would be best for very small images.

 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      05-12-2007
ASM wrote:
> Where to find some more informations about this
> href="data:application/vnd.ms-excel;base64,..." ?


http://en.wikipedia.org/wiki/Data:_URI_scheme

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ Topic - What questions are on-topic for CLJ? (2008-10-16) FAQ server Javascript 1 10-16-2008 12:03 PM
Submitted papers for the Conference: 489. Accepted papers: 158. Fromthem 6 BEST papers are also accepted to the WSEAS journals Kostas I. C++ 0 11-29-2007 11:03 AM
Submitted papers for the Conference: 489. Accepted papers: 158. Fromthem 6 BEST papers are also accepted to the WSEAS journals shuchen. C Programming 0 11-29-2007 10:59 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM



Advertisments