title: Open a pdf content in a new browser tab
body: <p>I have a GET Ajax Request, that returns me a content, coded in application/pdf form. 
  For example, my requests returns a string of this type: </p>
  
  <blockquote>
    <p>%PDF-1.4 %���� 4 0 obj &lt;>stream
    x��        endstream endobj 6 0 obj &lt;>stream x���]o�0���+�e{Q�$��R�N� ������@-
    ���n��wBL$.JDL|�>獝��[�
    �>{���=_ʻ(寒����1`ؚyW��G���XϽo�1�6��Ӳ.�4(u�C��8�j���H�l�����f6*k�Fa^�e�G=��J0��}
    7L�z�ͺ��p�H����&amp;�ɴ�L�Z �</p>
  </blockquote>
  
  <p>Excuse me for special characters rendered badly: the problem is just that. I would like to take this response, obtained from my request, and print this content correctly in another browser tab. I wrote the code to do this: I used the Blob object. The page for "reading the pdf" is properly opened. However, I see only a pdf document which is completely white, a sign of the fact that my response was not written on the document that has been created. </p>
  
  <p>Below I show you the code of my request:</p>
  
  <pre><code>$.ajax({
      type: "GET",
      url:urll + parameter,
      async: true,
      crossDomain: true,
      accept: {
            pdf: 'application/pdf'
      },
      success:function(response, status, xhr){
  
          alert("Response: "+response);
          alert("Status: "+status);
          alert("Xhr: "+xhr);
  
          // check for a filename
          var filename = "";
          var disposition = xhr.getResponseHeader('Content-Disposition');
          if (disposition &amp;&amp; disposition.indexOf('attachment') !== -1) {
              var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
              var matches = filenameRegex.exec(disposition);
              if (matches != null &amp;&amp; matches[1]) filename = matches[1].replace(/['"]/g, '');
          }
  
          var type = xhr.getResponseHeader('Content-Type');
          var blob = new Blob([response], { type: type });
  
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
              // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
              window.navigator.msSaveBlob(blob, filename);
          } else {
              var URL = window.URL || window.webkitURL;
              var downloadUrl = URL.createObjectURL(blob);
  
              if (filename) {
                  // use HTML5 a[download] attribute to specify filename
                  var a = document.createElement("a");
                  // safari doesn't support this yet
                  if (typeof a.download === 'undefined') {
                      //window.location = downloadUrl;
                      window.open(downloadUrl, '_blank');
                  } else {                        
                      a.href = downloadUrl;
                      a.download = filename;
                      document.body.appendChild(a);
                      a.setAttribute("target","_blank");
                      a.click();
                  }
              } else {
                  //window.location = downloadUrl;
                  window.open(downloadUrl, '_blank');
              }
  
              setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup
          }
      },
      error: function(xhr,status,error){
          alert("error "+xhr+" "+error+" "+status);
      }
  });
  </code></pre>