<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Saving files with Javascript?</title>
	<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript/</link>
	<description>Comments on Ask MetaFilter post Saving files with Javascript?</description>
	<pubDate>Sun, 19 Mar 2006 08:34:27 -0800</pubDate>
	<lastBuildDate>Sun, 19 Mar 2006 08:34:27 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Saving files with Javascript?</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript</link>	
		<description>Are there any tutorials out there that explains how to save/update files from a browser using only javascript as &lt;a href=&quot;http://www.tiddlywiki.com/&quot;&gt;tiddlywiki&lt;/a&gt; does? &lt;br /&gt;&lt;br /&gt; (I tried to figure it out from the tiddlywiki source code without luck...)</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.34651</guid>
		<pubDate>Sun, 19 Mar 2006 08:31:07 -0800</pubDate>
		<dc:creator>gwint</dc:creator>
		
			<category>javascript</category>
		
			<category>tiddlywiki</category>
		
	</item> <item>
		<title>By: charmston</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#539968</link>	
		<description>&lt;a href=&quot;http://www.google.com/search?q=ajax%20tutorials&quot;&gt;Google loves you&lt;/a&gt;.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-539968</guid>
		<pubDate>Sun, 19 Mar 2006 08:34:27 -0800</pubDate>
		<dc:creator>charmston</dc:creator>
	</item><item>
		<title>By: scottreynen</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#539985</link>	
		<description>charmston, are you sure tiddlywiki is using AJAX? I don&apos;t see any AJAX calls in a quick skim of the source.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-539985</guid>
		<pubDate>Sun, 19 Mar 2006 08:58:20 -0800</pubDate>
		<dc:creator>scottreynen</dc:creator>
	</item><item>
		<title>By: charmston</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#539987</link>	
		<description>I&apos;ve never looked into the tiddlywiki source, but AJAX will do as he asked: &lt;em&gt;&quot;save/update files from a browser using only javascript&quot;&lt;/em&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-539987</guid>
		<pubDate>Sun, 19 Mar 2006 09:00:20 -0800</pubDate>
		<dc:creator>charmston</dc:creator>
	</item><item>
		<title>By: cyrusdogstar</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#539999</link>	
		<description>Actually, to my knowledge, JS &lt;b&gt;cannot&lt;/b&gt; manipulate client-side files/folders due to security constraints--I recall attempting to set up a script to cause the browser to access a local drive, and both Firefox and IE spat out security errors. I mean, think about what could happen if JS alone was capable of such things--you&apos;d have websites that could erase your files!&lt;br&gt;
&lt;br&gt;
Upon further examination, I appear to be correct--TiddlyWiki requires you to &lt;b&gt;manually save it to your hard disk&lt;/b&gt; to get a local version, which you then may edit and save (and I&apos;ll note that the browsers &lt;i&gt;still&lt;/i&gt; throw fits when this &lt;b&gt;local&lt;/b&gt; version tries to save, although you may then opt to allow the action--which you cannot do for a remote script).&lt;br&gt;
&lt;br&gt;
So if what you want is a JavaScript sitting on your Web server to manipulate files on the browser&apos;s machine, I think you&apos;re out of luck. I could be wrong, of course, but this is what I think I know :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-539999</guid>
		<pubDate>Sun, 19 Mar 2006 09:32:35 -0800</pubDate>
		<dc:creator>cyrusdogstar</dc:creator>
	</item><item>
		<title>By: cyrusdogstar</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540000</link>	
		<description>&lt;b&gt;charmston:&lt;/b&gt; I think you might be confused, no offense intended if I&apos;m wrong--AJAX is used to update &lt;i&gt;server-side&lt;/i&gt; files via JS, &lt;b&gt;not&lt;/b&gt; client-side files.&lt;br&gt;
&lt;br&gt;
So I guess it all depends on what specifically you want, &lt;b&gt;gwint&lt;/b&gt;--do you want JS that can save to your local machine, or to the Web server the JS is hosted on? If the former, see my first comment, and if the latter, then charmston is right and you want to be using AJAX (which is unfortunately &lt;b&gt;not&lt;/b&gt; entirely JavaScript, but requires some server-side technology to pair with, although you can pick and choose various implementations in several languages).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540000</guid>
		<pubDate>Sun, 19 Mar 2006 09:35:11 -0800</pubDate>
		<dc:creator>cyrusdogstar</dc:creator>
	</item><item>
		<title>By: cyrusdogstar</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540002</link>	
		<description>&lt;small&gt;&lt;small&gt;Sorry for all the bolding and italics, I&apos;m in a strongly emphasizing mood today, I guess =)&lt;/small&gt;&lt;/small&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540002</guid>
		<pubDate>Sun, 19 Mar 2006 09:35:59 -0800</pubDate>
		<dc:creator>cyrusdogstar</dc:creator>
	</item><item>
		<title>By: gwint</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540042</link>	
		<description>My understanding is that tiddlywiki allows both-- if the file is on a server, it updates the file on the server, if you have the file locally, it saves it locally, without ajax (i.e. without the use of XMLHttpRequest.)  The &quot;magic&quot; of tiddlywiki is that all of the code to do this is within the file being changed-- and it&apos;s all javascript. (I think that&apos;s also how it gets around the security issues-- you can only manipulate the specific file you&apos;re triggering the code from?)&lt;br&gt;
&lt;br&gt;
So anyway, it&apos;s clear that one &lt;b&gt;can&lt;/b&gt; have a file updated/saved from a browser using only javascript because this is what tiddlywiki does.  I&apos;m just not sure how...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540042</guid>
		<pubDate>Sun, 19 Mar 2006 10:46:18 -0800</pubDate>
		<dc:creator>gwint</dc:creator>
	</item><item>
		<title>By: gwint</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540043</link>	
		<description>Also, &lt;b&gt;cyrusdogstar&lt;/b&gt;, I&apos;m not sure what &quot;I&apos;ll note that the browsers still throw fits when this local version tries to save&quot; means for you, but when I use tiddlywiki both locally or online, I can save (i.e. update the file) from within the browser and it just works-- I click the &quot;done&quot; button and the file is updated without a peep from the browser.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540043</guid>
		<pubDate>Sun, 19 Mar 2006 10:50:05 -0800</pubDate>
		<dc:creator>gwint</dc:creator>
	</item><item>
		<title>By: blag</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540054</link>	
		<description>I get 2 or 3 security warnings when I use the &quot;Save changes&quot; function within a locally-installed TiddlyWiki (FF). However, there is a &lt;em&gt;&quot;Don&apos;t warn me about this again&quot;&lt;/em&gt; checkbox - maybe you ticked this a while ago and forgot about it?&lt;br&gt;
&lt;br&gt;
Also, are you sure about the saving on a server thing? I was under the impression that you needed a &lt;a href=&quot;http://www.bidix.info/TiddlyWiki/BidiXTW.html#UploadPlugin&quot;&gt;plugin &lt;/a&gt;for that.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540054</guid>
		<pubDate>Sun, 19 Mar 2006 11:33:42 -0800</pubDate>
		<dc:creator>blag</dc:creator>
	</item><item>
		<title>By: evariste</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540068</link>	
		<description>To get TiddlyWiki working in Opera, you have to &lt;a href=&quot;http://my.opera.com/forums/showthread.php?s=&amp;threadid=91372&amp;highlight=GTDTiddlyWiki&quot;&gt;create a Java* security policy file&lt;/a&gt; that permits it to save locally. In IE, it uses some ActiveX method, and I&apos;m not sure what it does in Firefox.&lt;br&gt;
&lt;br&gt;
&lt;small&gt;*not java&lt;i&gt;script,&lt;/i&gt; Java....&lt;/small&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540068</guid>
		<pubDate>Sun, 19 Mar 2006 11:55:24 -0800</pubDate>
		<dc:creator>evariste</dc:creator>
	</item><item>
		<title>By: gwint</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540072</link>	
		<description>I&apos;m using Firefox, and &lt;b&gt;blag&lt;/b&gt;, I believe you&apos;re right-- I think the first time I used it I got an alert.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540072</guid>
		<pubDate>Sun, 19 Mar 2006 12:01:18 -0800</pubDate>
		<dc:creator>gwint</dc:creator>
	</item><item>
		<title>By: Rhomboid</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540111</link>	
		<description>TiddlyWiki can in fact save to local files.  It will only do this when it&apos;s saved already as a local file and loaded in the browser as a &quot;file://&quot; URL.  AJAX is a complete red herring here, and has absolutely nothing to do with the question at all.&lt;br&gt;
&lt;br&gt;
The main file reading/writing functions are &lt;tt&gt;saveFile()&lt;/tt&gt; and &lt;tt&gt;loadFile()&lt;/tt&gt;.  These however are just glue around the browser-specific implementations of each of these functions: &lt;tt&gt;safariSaveFile(), safariLoadFile(), mozillaSaveFile(), mozillaLoadFile(), ieSaveFile(), ieLoadFile(), operaSaveFile(), operaLoadFile()&lt;/tt&gt;.  If you search for those functions you can see how each is implemented.  Here is one:&lt;br&gt;
&lt;pre&gt;// Returns null if it can&apos;t do it, false if there&apos;s an error, true if it saved OK&lt;br&gt;function mozillaSaveFile(filePath, content)&lt;br&gt;{&lt;br&gt;    if(window.Components)&lt;br&gt;        try&lt;br&gt;            {&lt;br&gt;            netscape.security.PrivilegeManager.enablePrivilege(&quot;UniversalXPConnect&quot;);&lt;br&gt;            var file = Components.classes[&quot;@mozilla.org/file/local;1&quot;].createInstance(Components.interfaces.nsILocalFile);&lt;br&gt;            file.initWithPath(filePath);&lt;br&gt;            if (!file.exists())&lt;br&gt;                file.create(0, 0664);&lt;br&gt;            var out = Components.classes[&quot;@mozilla.org/network/file-output-stream;1&quot;].createInstance(Components.interfaces.nsIFileOutputStream);&lt;br&gt;            out.init(file, 0x20 | 0x02, 00004,null);&lt;br&gt;            out.write(content, content.length);&lt;br&gt;            out.flush();&lt;br&gt;            out.close();&lt;br&gt;            return(true);&lt;br&gt;            }&lt;br&gt;        catch(e)&lt;br&gt;            {&lt;br&gt;            //alert(&quot;Exception while attempting to save\n\n&quot; + e);&lt;br&gt;            return(false);&lt;br&gt;            }&lt;br&gt;    return(null);&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540111</guid>
		<pubDate>Sun, 19 Mar 2006 13:31:23 -0800</pubDate>
		<dc:creator>Rhomboid</dc:creator>
	</item><item>
		<title>By: charmston</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540480</link>	
		<description>&lt;a href=&quot;http://ask.metafilter.com/mefi/34651#540000&quot;&gt;cyrus&lt;/a&gt;: ajax is used to execute (not &quot;write to&quot;) server-side scripts with given paramaters. If I&apos;m not mistaken, most &lt;a href=&quot;http://www.phpnoise.com/tutorials/20/3&quot;&gt;server-side languages&lt;/a&gt; &lt;a href=&quot;http://www.freevbcode.com/ShowCode.Asp?ID=89&quot;&gt;can write&lt;/a&gt; &lt;a href=&quot;http://www.zenspider.com/Languages/Ruby/QuickRef.html#14&quot;&gt;to files&lt;/a&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540480</guid>
		<pubDate>Sun, 19 Mar 2006 23:06:59 -0800</pubDate>
		<dc:creator>charmston</dc:creator>
	</item><item>
		<title>By: yerfatma</title>
		<link>http://ask.metafilter.com/34651/Saving-files-with-Javascript#540594</link>	
		<description>It looks like TW does it &lt;a href=&quot;http://ajaxian.com/archives/ms-html-applications&quot;&gt;this way.&lt;/a&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.34651-540594</guid>
		<pubDate>Mon, 20 Mar 2006 04:51:48 -0800</pubDate>
		<dc:creator>yerfatma</dc:creator>
	</item>
	</channel>
</rss>
