From: Bwig Zomberi on
Michael Haufe ("TNO") wrote:
>
> Regardless, the claim that "It is not possible with client-side
> javascript." is inaccurate and should be changed to mention the
> approaches used through base64 and document.execCommand("SaveAs"...)
>
> The details on what warrants an appropriate example should be separate
> debate I think.

document.execCommand("SaveAs"...) probably works only for the entire web
page, not for a mime type.

--
Bwig Zomberi
From: Garrett Smith on
Michael Haufe ("TNO") wrote:
> On Apr 26, 10:21 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
>> I recall another discussion where there was mention of a way to get a
>> similar effect from IE, however nobody wrote a cross browser solution.
> [...]
>> I recall another discussion where there was mention of a way to get a
>> similar effect from IE, however nobody wrote a cross browser solution.
>
> http://thenewobjective.com/temp/save2.html
>
> This seems to work on all common browsers minus Chrome (where I can't
> tell if this is a bug or intentional behavior).
>

Try putting base64 first in the uri before the content type.
http://en.wikipedia.org/wiki/Data_URI_scheme#Format

Also: "charset ignored in data URIs when data is encoded via base64"
http://code.google.com/p/chromium/issues/detail?id=35582&q=base64%20data&colspec=ID%20Stars%20Pri%20Area%20Feature%20Type%20Status%20Summary%20Modified%20Owner%20Mstone%20OS

> Regardless, the claim that "It is not possible with client-side
> javascript." is inaccurate and should be changed to mention the
> approaches used through base64 and document.execCommand("SaveAs"...)
>
> The details on what warrants an appropriate example should be separate
> debate I think.

The FAQ question "asks how do I..." and so if there is to be an answer
the provides an explanation, it should be a good answer and have a good
example.

The example would have to be a solution where "Save As" dialog is
displayed to save a particular thing that the developer wants.

The butterfly seems to be a more likely case than saving the HTML
document itself. that can be done by setting an iframe source to the
image and then calling:
iframe.contentWindow.document.execCommand("SaveAs");

Needs work.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Bwig Zomberi on
Ry Nohryb wrote:
> On Apr 28, 6:38 am, "Michael Haufe (\"TNO\")"
> <t...(a)thenewobjective.com> wrote:
>> On Apr 26, 10:21 pm, Garrett Smith<dhtmlkitc...(a)gmail.com> wrote:
>>
>> The details on what warrants an appropriate example should be separate
>> debate I think.
>
> That's awesome: you set the location.href (.src) on an iframe to be a
> data uri with mimetype application/octet-stream so that it gets
> downloaded automatically. My browser decodes the base64 encoded
> contents and saves it -but without asking anything- as an "unknown"
> file of unknown filetype. Well, it's ok, I know it's an html. But for
> exactly what type of contents would this trick work well beyond
> texts ? If the XHR were for a .png, would it work too ? And is there
> anyway to type the downloaded file (add its .png) ? I guess not,
> right ? I wonder if not presenting a save as dialog, as in Safari,
> could/should be considered a bug. An evil page could do this:

Browser will have to show a dialog box. Otherwise it is a bug. Maybe you
have set Safari not to show any prompts. - "Do not show this prompt
again. Remember this setting."

--
Bwig Zomberi
From: Ry Nohryb on
On Apr 28, 1:49 pm, Bwig Zomberi <zomberiMAPSONNOS...(a)gmail.com>
wrote:
>
> Browser will have to show a dialog box. Otherwise it is a bug. Maybe you
> have set Safari not to show any prompts.  - "Do not show this prompt
> again. Remember this setting."

I can't seem to find that preference.. :-( Have you got a Safari to
check it out ? And yes, the dialog pops up in every other browser.

@TNO: For u:

// Modificado por jorge(a)jorgechamorro.com para detectar webkit's
base64 nativo (atob,btoa)
// Code was written by Tyler Akins and is placed in the public domain
// It would be nice if you left this header. http://rumkin.com


if (!window.btoa) {
window.btoa= function btoa (input) {
var base64_keyStr=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;

do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);

enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;

if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}

output = output + base64_keyStr.charAt(enc1) +
base64_keyStr.charAt(enc2) +
base64_keyStr.charAt(enc3) + base64_keyStr.charAt(enc4);
} while (i < input.length);

return output;
};
}

if (!window.atob) {
window.atob= function atob (input) {
var base64_keyStr=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;

// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

while (i < input.length) {
enc1 = base64_keyStr.indexOf(input.charAt(i++));
enc2 = base64_keyStr.indexOf(input.charAt(i++));
enc3 = base64_keyStr.indexOf(input.charAt(i++));
enc4 = base64_keyStr.indexOf(input.charAt(i++));

chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;

output = output + String.fromCharCode(chr1);

if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}

return output;
};
}
--
Jorge.
From: Bwig Zomberi on
Ry Nohryb wrote:
> On Apr 28, 1:49 pm, Bwig Zomberi<zomberiMAPSONNOS...(a)gmail.com>
> wrote:
>>
>> Browser will have to show a dialog box. Otherwise it is a bug. Maybe you
>> have set Safari not to show any prompts. - "Do not show this prompt
>> again. Remember this setting."
>
> I can't seem to find that preference.. :-( Have you got a Safari to
> check it out ? And yes, the dialog pops up in every other browser.
>


Safari does not seem to allow editing of mime-type handling. There is
the option of saving to a folder in Preferences -> General. That's it.