HighDots Forums  

Re: Possible to generate text files in javascript?

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Possible to generate text files in javascript? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Possible to generate text files in javascript? - 12-14-2007 , 03:10 PM






VK wrote:
Quote:
On Dec 13, 9:38 pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de
wrote:
MSHTML-based user agents at least since version 4.0 (e.g. IE 4.0+ for
Windows) and Gecko-based UAs since version 1.8 (e.g. Firefox 1.5+) [1] support

document.open("text/plain");
document.write("foo\nbar");
document.close();

Yeah, I forgot to mention: that is your fantasy, IE never supported
anything but "text/html" for MIME in document.open method.
You are confusing things, the expert on publishing fantasies is *you*.
I have of course *tested* the above statement positive in the following UAs:

Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202})

Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)

Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)

Except of IE 7, these are the standalone versions of course, however I have
also tested other DOM features with these and observed the expected result;
e.g. document.getElementById() was not supported in Standalone IE 4.01 but
since 5.01.

Quote:
Actually MSDN is very explicit about it as well:

http://msdn2.microsoft.com/en-us/library/ms536652.aspx
"text/html Default. Currently the only MIME type supported for this
method."
The MSDN Library is incorrect then.

Quote:
By using document.open('text/plain') one trigs "unsupported MIME type
argument protection" in IE with some very funny consequences.
Utter nonsense.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
  #2  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Possible to generate text files in javascript? - 12-14-2007 , 05:20 PM






VK wrote:
Quote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
VK wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
MSHTML-based user agents at least since version 4.0 (e.g. IE 4.0+ for
Windows) and Gecko-based UAs since version 1.8 (e.g. Firefox 1.5+) [1] support
document.open("text/plain");
document.write("foo\nbar");
document.close();
Yeah, I forgot to mention: that is your fantasy, IE never supported
anything but "text/html" for MIME in document.open method.
You are confusing things, the expert on publishing fantasies is *you*.
I have of course *tested* the above statement positive

You may rethink your idea of "positive test" a.s.a.p. then.
With your providing an inappropriate (and syntactically invalid) test case?
Certainly not.

Quote:
var w = window.open('about:blank');
Why do you introduce `about:blank', another, possibly incompatible,
pseudo-protocol?

Quote:
/* timeout is only to avoid
* ideas of page not ready yet
* and similar
*/
window.setTimeout('f()',1000);
function f() {
w.document.clear();
Why do you introduce another now-proprietary[1] feature? And why do you
call the method *before* opening the output stream -- a method about which
the MSDN Library states:

Quote:
clear Method

Not currently supported. To clear all elements in the current document,
use document.write(""), followed by document.close."

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document
Object Model (DOM) Level 1 World Wide Web [DOM].
?

[1] <http://www.w3.org/TR/DOM-Level-2-HTML/>
"Status of this Document" --> "Note"

Quote:
w.document.open('text/plain');
w.document.write('foo\nbar');
w.document.close();
}
/script
/body
/html

1) Open the page in IE 6.
2) In the popup window wait a sec until "foo bar" text appears.
3) In the popup window choose File / Save As... /
4) Default file type is HTML, not TEXT
Apparently you have not been paying attention. I have said that with

document.execCommand("SaveAs", ...)

the filename suffix is .html and file content is HTML but if you provide
`.txt' as suffix it is actually saved as plain text by default. Of course
that behavior is the same with the menu item that triggers this
functionality if the same "File type" option is selected.

Quote:
5-a) Click OK and observe that the saved page is not from pupup, but
the stating one with the script - but converted to Unicode with BOM in
front of the first tag. No foo, no bar.
That is true, but ...

Evidently now, you have not been paying attention. I have used
document.execCommand() to trigger the "Save As" operation, not
the menu option (in fact, my popup does not even need a menu bar).

I recognize that there is a bug with the "Save As" menu item and the "Web
page, complete (*.htm;*.html)" and "Web page, single file (*.mht)" "File
type" option in IE, however that is irrelevant here as I did not propose to
use either one. (Besides, the OP wanted the user to save something as text,
so even if they do not implement the document.execCommand() suggestion, it
is unlikely that the user will leave the "File type" option at "HTML"; so it
is unlikely that the bug occurs.)

A (proper) test case can now be found at
http://PointedEars.de/scripts/test/dom/text-save

Quote:
5-b) Manually change to Text File and save. OK, kind of working but
still in Unicode (line breaks mistreated if no Unicode support in the
text viewer).
Nothing is wrong with saving as "Unicode" text (which is then actually
UTF-16LE-encoded text without BOM). Even, and especially, the Windows
Notepad (at least since Windows 2000) can display that properly. (In fact,
ECMAScript 3 implementations use that encoding internally for parsing code
and storing string values.)

Quote:
5-c) Instead of "about:blank" use an initial text file. Observe no
difference in the behavior.
6) Enjoy.
ISTM you enjoy to boldly present your misconceptions where no one presented
them before[tm], and be corrected each and every single time.


PointedEars
___________
[tm] I am allowed to make that kind of pun ;-)
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7 (AT) news (DOT) demon.co.uk>


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.