title: HTML5 JavaScript Download attribute
body: <p>I have been working on a project for a couple months now and I am nearing the end of it. One of the last steps is to provide a file which will be filled with information which has been generated by actions of the user during their session.
  <a href="https://stackoverflow.com/questions/4309958/can-i-write-files-with-html5-js">Can I write files with HTML5/JS?</a>
  and the answer by ecmanaut has gotten me very close since he provided two methods of doing so, one in pure html5 and one using JavaScript.</p>
  
  <p>I had first used the JavaScript method which would only work in Chrome, not in Mozilla or IE. So I used the pure html5 method combined with some alternate JavaScript to paste it to the page so it was click-able.</p>
  
  <pre><code>document.getElementById('download').innerHTML = '&lt;a id="save" download="earth.txt" href="data:text/plain,mostly harmless&amp;#10;and a bit more"&gt;Save&lt;/a&gt;';
  </code></pre>
  
  <p>This code creates a file which is downloaded, but does not contain the newline which the article said was '&#10;'. So I did a search to see what other character codes could be recognized. <a href="http://en.wikipedia.org/wiki/Newline" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Newline</a> provided me with many possible choices, none that I have tried have worked. The ones I have tried are: '&amp;#10', '&#10;', '&amp;#13', '&#13;', '\r\n', '\r', '\n', '\cr', '\c\r', 0x0D, 0x0A, 0c0D0A. In many of the cases the newline was removed and nothing would appear.</p>
  
  <p>While testing the above code, it works in Mozilla and Chrome (minus the newline), but the result in IE is different. When you click on the Save link, it actually moves to the page and has the url as what the data contents are.</p>
  
  <p>While the project might be acceptable without this feature working, I would very much like to get it working after having spent so much time and effort on it and having gotten so close. I also need to test this in Safari but I have not done any testing in that browser yet. Browser support required from most important to least is as follows: Mozilla, Chrome, Safari, IE. If possible I would like to avoid browser specific coding.</p>
  
  <p>I should also mention that like in the first link, I do not want to send to a server to have the download, I need it working locally on the client side with no server interaction.</p>
  
  <p>So to sum up, I need at least to get the newline working for the file so that Mozilla and Chrome are both fully working. And if possible, a way to get the file working in IE as well.</p>
  
  <p>Edit: Nov 3, 2014 1:40pm Local Time
  I have tried the suggested edit by maths4js about changing around my quotes and the suggestion did not work. It came to my attention that submitting a larger sample page of code would be a helpful idea. It was also suggested that I look to see which browsers support this feature <a href="http://caniuse.com/#feat=download" rel="nofollow noreferrer">http://caniuse.com/#feat=download</a> and it appears that IE and Safari do not, so I will not worry about them at the moment and maybe down the road have browser specific coding for them.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt;&lt;style&gt;body{margin: 0px;padding: 0px;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;center&gt;&lt;br&gt;&lt;div id='download'&gt;&lt;/div&gt;&lt;/center&gt;
  &lt;script&gt;
  function download(){
  //var newline= '&amp;#10';  //no line breaks
  //var newline= '&amp;#10;'; //no line breaks
  //var newline= "&amp;#10;"; //no line breaks
  //var newline= "&amp;#10";          //no line breaks
  //var newline= "\r\n";      //no line breaks
  //var newline= "\r\n;";     //appends ; but no line breaks
  //var newline = '\n';       //no line break 
  //var newline = '/n';   //completely failed
  var newline = 0x0D0A;
  var tab = "       ";
  var text = "Title of the document" + newline;
  text += "Just a line of text : ";
  text = text +"Random";
  text = text + newline + "Trial" + tab + "Time" + tab + "Correct" + newline;
  //document.getElementById('download').innerHTML = '&lt;a id="save" download="This_File.txt" href="data:text/plain,'+text+'"&gt;Save&lt;/a&gt;';
  //document.getElementById('download').innerHTML = '&lt;a id="save" download="earth.txt" href="data:text/plain,mostly harmless&amp;#10;and a bit more"&gt;Save&lt;/a&gt;';
  document.getElementById('download').innerHTML = "&lt;a id='save' download='earth.txt' href='data:text/plain,mostly harmless&amp;#10;and a bit more'&gt;Save&lt;/a&gt;";
  }
  download();
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;      
  </code></pre>
  
  <p>I would like to thank you all for the effort and time you have given me already.</p>