title: In JQuery check if window.open streamed file contents to a new window sucessfully
body: <p>When a user clicks on a document icon, I am opening/streaming the document in a new window using window.open.  The call returns windowObjectReference which gives me access to the child window.  However if the child window failed to open a document such as a pdf in a pdf viewer because it was not installed on the local machine, how can I determine that the document failed to open in a suitable viewer such as PDF Viewer or Word etc.  The code below shows the javascript function I am using.</p>
  
  <pre><code>function LoadDocument(id) {
          $.ajax({
              cache: false,
              type: "GET",
              url: 'Dashboard/GetDocument',
              contentType: 'application/json',
              data: { "id": id },
              success: function (data, textStatus, jqXHR) {
                  doc = data;
                  if (data !== undefined) {
                      if (doc.Result == true) {
  
                          var windowObjectReference = window.open("data:" + doc.ContentType + ";base64, " + doc.Document, '', 'height=650,width=840,resizable,scrollbars=yes,status=1');
  
                           if (windowObjectReference  === undefined) {
                              var a = document.createElement("a");
                              a.href = "data:application/octet-stream;charset=utf-8;base64," + doc.Document;
                              a.download = doc.Filename;
                              document.body.appendChild(a);
                              a.click();
                          }
  
                      }
                      else {
                          alert('Unable to obtain the document from the database.');
                      }
                  }
                  else
                  {
                      alert('Unable to load the document.');
                  }
              },
              error: function (xhr) {
                  alert("Error occurred while loading the avatar image. "
                      + xhr.responseText);
              }
          });
      }
  </code></pre>
  
  <p>The windowObjectReference returns an object instance even when a document fails to load in a new window.  Is there some other way to check if the window.open method failed?</p>