title: browser independent file io in javascript
body: <p>I have searched religiously here and elsewhere online for resolution to my problem to no avail. I have found many code snippets with samples from javascript to jquery that claim to be able to create and write to a txt or html file, but none of them have worked for me. Here is my issue... </p>
  
  <p>I have a nice little very light php (or html) page that uses a javascript API to record a video, upload it to a server in the cloud and provide me with a token by which I can access that video for playback. It works very nicely to that point.</p>
  
  <p>What I'm trying to do is capture the javascript variable containing the token, then create a new html (or php) file that contains the very simple code using that token to display the video.</p>
  
  <p>Here's the essense of the code...</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" href="//assets.ziggeo.com/css/ziggeo-betajs-player.min.css" /&gt;
  &lt;script src="//assets.ziggeo.com/js/ziggeo-jquery-json2-betajs-player.min.js"&gt;
  &lt;/script&gt;
  &lt;script&gt;
  ZiggeoApi.token = "883afacbe59949feae1c9c661d653257";
  ZiggeoApi.Events.on("submitted", function (data) {
      var token = '&lt;ziggeo ziggeo-video=' + data.video.token + '&gt;';
      document.getElementById("output").innerHTML=token;
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;!-- next line displays the recorder --&gt;
  &lt;ziggeo&gt;&lt;/ziggeo&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;font color=black&gt;
  &lt;!-- next line displays the recorded video using the generated token for id --&gt;
  &lt;p id='output'&gt;&lt;/p&gt;
  &lt;/font&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>...in the above, after a video is created the ZiggeoApi.Events.on("submitted"... line returns the token in data.video.token. I then am trying to do rather than show the video on the same page in an element identified by "id" is output the code in the head section plus this in the body section of a new html file...
      ''
  ...but every javascript effort to do that has failed. No errors, no complaints, and no file. </p>
  
  <p>I tried converting the javascript variable data.video.token to a php variable, because I know I can make php write the file. I have working code for that, except the conversion of the javascript var to a php var isn't working either.</p>
  
  <p>Any help appreciated.</p>
  
  <p>Here are some samples of code I've tried to get the file to write...</p>
  
  <pre><code>&lt;script&gt;
  var txtFile = "test.html";
  var file = new File(txtFile);
  var str = '&lt;ziggeo ziggeo-video=' + data.video.token + '&gt;';
  file.open("w"); // open file with write access
  file.write(str);
  file.close();
  &lt;/script&gt;
  </code></pre>
  
  <p>...above didn't work...</p>
  
  <pre><code>&lt;script&gt;
  import System.IO;
  import System;  // Used for getting the date
  function Start () {
      // Create an instance of StreamWriter to write text to a file.
      sw = new StreamWriter("/home4/htlwoadm/public_html/ziggeo/test.txt");
      // Add some text to the file.
      sw.Write("This is the ");
      sw.WriteLine("header for the file.");
      sw.WriteLine("-------------------");
      // Arbitrary objects can also be written to the file.
      sw.Write("The date is: ");
      sw.WriteLine(DateTime.Now);
      sw.Close();
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>...above didn't work at all... so didn't try to modify it...</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
  WriteFile();
  &lt;/script&gt;
  &lt;script&gt;
  function WriteFile()
  {
          var fh = fopen("test.html", 3); // Open the file for writing
          if(fh!=-1) // If the file has been successfully opened {
                  var str = "Some text goes here...";
                  fwrite(fh, str); // Write the string to a file
                  fclose(fh); // Close the file
          }
  
  }
  &lt;/script&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>...above also didn't work so didn't modify it either...</p>
  
  <pre><code>&lt;?php
  $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
  $txt = "John Doe\n";
  fwrite($myfile, $txt);
  $txt = "Jane Doe\n";
  fwrite($myfile, $txt);
  fclose($myfile);
  ?&gt;
  </code></pre>
  
  <p>...above works, but can't seem to get the javascript variable up above (data.video.token) to convert to php so haven't modified it either.</p>
  
  <p>Any help appreciated.</p>