title: Download pdf file from ajax response
body: <p>I'm trying to make the browser download a pdf file received from an ajax response. </p>
  
  <p>Inspired by <a href="https://stackoverflow.com/questions/34586671/download-pdf-file-using-jquery-ajax">Download pdf file using jquery ajax</a> I simulate a click/download event like this:</p>
  
  <pre><code>    var req = new XMLHttpRequest();
      req.open("POST", "/servicepath/Method?ids=" + ids, true);
      req.responseType = "blob";
      req.onreadystatechange = function () {
          if (req.readyState === 4 &amp;&amp; req.status === 200) {
              var blob = req.response;
              var link = document.createElement('a');
              link.href = window.URL.createObjectURL(blob);
              link.download = "PdfName-" + new Date().getTime() + ".pdf";
              link.click();
          }
      };
      req.send();
  </code></pre>
  
  <p>Unfortunately this only works in Chrome, but not Firefox + IE. Nothing happens when I try to trigger it in the last two browsers. </p>
  
  <p>The script and markup is placed inside an iframe due to inheritance from an CMS, but I'm not sure if that has any influence a.</p>
  
  <p><strong>Any idea on how to optimize it for all modern browsers?</strong></p>