473,573 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

-----------------------------------------------------------------------
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=filena me.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.javas cript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.

May 11 '07 #1
60 7917
FAQ server wrote on 12 mei 2007 in comp.lang.javas cript:
-----------------------------------------------------------------------
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=filena me.ext `
<script language='jscri pt' runat='server'//ASP-enabled server needed
Response.AddHea der('content-disposition','a ttachment;filen ame=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)
May 12 '07 #2
On May 12, 9:07 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
FAQ server wrote on 12 mei 2007 in comp.lang.javas cript:
-----------------------------------------------------------------------
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=filena me.ext `

<script language='jscri pt' runat='server'//ASP-enabled server needed
Response.AddHea der('content-disposition','a ttachment;filen ame=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:appl ication/vnd.ms-excel;base64,MS wyLDMsNA=="
target="file">c lick here</a>
</body>
</html>

May 12 '07 #3
shimmyshack wrote:
<html>
<head></head>
<body>
<iframe frameborder="0" width="0" height="0" src="" id="file"
name="file"></iframe>
<a href="data:appl ication/vnd.ms-excel;base64,MS wyLDMsNA=="
target="file">c lick 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.
May 12 '07 #4
On May 12, 12:13 pm, -Lost <maventheextraw o...@techie.com wrote:
shimmyshack wrote:
<html>
<head></head>
<body>
<iframe frameborder="0" width="0" height="0" src="" id="file"
name="file"></iframe>
<a href="data:appl ication/vnd.ms-excel;base64,MS wyLDMsNA=="
target="file">c lick 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_conten ts( 'http://groups.google.c om/groups/img/gicons/
science_n_techn ology_42.gif' );
#$mime = 'image/gif'; #true mimetype
$mime = 'application/x-unknown'; #arbitrary one
?>
<a href="data:data :<?php echo $mime; ?>;base64,<?ph p echo
base64_encode($ data);?>" target="file">c lick 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.

May 12 '07 #5
ASM
shimmyshack a écrit :
>
<html>
<head></head>
<body>
<iframe frameborder="0" width="0" height="0" src="" id="file"
name="file"></iframe>
<a href="data:appl ication/vnd.ms-excel;base64,MS wyLDMsNA=="
target="file">c lick 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:appl ication/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
May 12 '07 #6
On May 12, 2:16 pm, ASM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
shimmyshack a écrit :
<html>
<head></head>
<body>
<iframe frameborder="0" width="0" height="0" src="" id="file"
name="file"></iframe>
<a href="data:appl ication/vnd.ms-excel;base64,MS wyLDMsNA=="
target="file">c lick 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:appl ication/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

May 12 '07 #7
ASM
shimmyshack a écrit :
>
<html>
<body>
<iframe frameborder="0" width="100" height="100" src="" id="file"
name="file"></iframe>
<?php
$data = file_get_conten ts( 'http://groups.google.c om/groups/img/gicons/
science_n_techn ology_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,<?ph p echo
base64_encode($ data);?>" target="file">c lick 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.locatio n.href='data:im age/gif;base64,'+
encodeBase64(do cument.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.ioswebdesig n.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
May 12 '07 #8
On May 12, 2:52 pm, ASM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
shimmyshack a écrit :
<html>
<body>
<iframe frameborder="0" width="100" height="100" src="" id="file"
name="file"></iframe>
<?php
$data = file_get_conten ts( 'http://groups.google.c om/groups/img/gicons/
science_n_techn ology_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,<?ph p echo
base64_encode($ data);?>" target="file">c lick 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.locatio n.href='data:im age/gif;base64,'+
encodeBase64(do cument.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.ioswebdesig n.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.

May 12 '07 #9
ASM wrote:
Where to find some more informations about this
href="data:appl ication/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.
May 12 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2977
by: dave | last post by:
Hi there I'm trying to force save as dialogue using this code in download.asp..but when it runs it prompts for download.asp to save or open. code snippet (from aspfaq.com) Response.ContentType = "application/x-unknown" ' arbitrary fn = "wallpaper_1_1.jpg" Response.write "<br>" & Server.MapPath("wallpaper") & "<br>" FPath =...
4
5530
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. When the user clicks to start the download I would like to display the "Save As" dialog, allow the user to name a place to save the file, and then...
6
1940
by: W.Guerlich | last post by:
I've got a Java servlet that delivers large database resultsets transformed to Excel with the HSSF library. In some cases it takes more than 15 minutes before transformation is done and content can be delivered to the browser. I want to show the "Save As" dialog as early as possible so the user knows he's not lost and forgotten. I...
3
6423
by: =?Utf-8?B?YXNkZg==?= | last post by:
Hello. I am making a web application with c# and am using this code: Response.ContentType = "application/x-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("あいうえお") + ".csv"); Encoding encoding = Encoding.GetEncoding("Shift-JIS"); Response.BinaryWrite(encoding.GetBytes(csvStr));...
0
7755
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7992
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8048
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5281
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3722
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2183
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.