title: How do I use link download attribute in FF and Chrome?
body: <p>After all of my research here and on other sites, I have arrived at the following code for saving some given text ("text" variable) with a given file name ("fileName" variable), but it only works perfectly in IE. Firefox downloads the file, but uses its own random name (like "G5QJNAr0"). And Chrome does nothing at all.</p>
  
  <pre><code>try {
      var blob = new Blob([text], {
           type: "text/csv;charset=utf-8"
      });
      if (window.navigator.msSaveOrOpenBlob) {
           window.navigator.msSaveBlob(blob, fileName);
      } else {
          var encodedData = encodeURI(text);
          var link = document.createElement("link");
          link.setAttribute("download", fileName);
          if ( 'URL' in window ) {
              link.setAttribute("href", window.URL.createObjectURL(blob));
              link.setAttribute("target", "_blank");
              link.style.display = "none";
              document.body.appendChild(link);
          } else if ( 'webkitURL' in window ) {
              link.setAttribute("href", window.webkitURL.createObjectURL(blob));
          }
          link.click();
      }
  } catch (e) {
      alert("Got error trying download text: " + e);
  }
  </code></pre>
  
  <p>No browser results in alerting the Exception.</p>
  
  <p>Chrome goes through all of the breakpoints I set and clicks the link at the end. But does absolutely nothing.</p>
  
  <p>Can someone help me with the filename and no-response problems in FF and Chrome, respectively?</p>