Check the file type returned by an HTTP GET request
<p>You would think my problem would be so commonplace that there would be solutions all over the internet for it. But I can't find anything that really answers my question.</p>

<p>Let me summarise my situation:</p>

<ul>
<li>I am using Open UI5.</li>
<li>I am coding an app which retrieves documents from various external websites. I want to display these documents inside my app, and not navigate to them, so I display the documents in an iframe. Haven't found any other way.</li>
<li>Some filetypes can be displayed natively, such as PDFs. Others, like Word, cannot - the easiest way I have found of displaying these is by using Google Docs, which implies changing the URL of the iframe's src from this :</li>
</ul>

<p><em><a href="http://example.com/my-target-doc.docx" rel="nofollow">http://example.com/my-target-doc.docx</a></em></p>

<p>to this:</p>

<p><em><a href="http://docs.google.com/gview?url=example.com/my-target-doc.docx&amp;embedded=true" rel="nofollow">http://docs.google.com/gview?url=example.com/my-target-doc.docx&amp;embedded=true</a></em></p>

<ul>
<li><p>Some of the external domains I retrieve the documents from require authentication. Therefore, I cannot set the iframe's src to <em><a href="http://docs.google.com/gview?url=example.com/my-target-doc.docx&amp;embedded=true" rel="nofollow">http://docs.google.com/gview?url=example.com/my-target-doc.docx&amp;embedded=true</a></em> directly - Google docs would attempt to display the authentication page. I must keep the original URL, and then, once the user's authenticated, replace the document URL with the Google docs version of the same URL.</p></li>
<li><p>What I am trying to do, then, is use the iframe's "onload" event to get the currently loaded page's address and, if it is a .doc/.docx/.ppt etc, replace that same URL with the GD version of the URL.</p></li>
<li><p>The difficulty is that there is no extension at the end of the URL which points to the document - none of the URLs I need to use end with ".doc", ".ppt" or whatever, so parsing the URL is out.</p></li>
</ul>

<p>So this is my question : Is there a way in Javascript to get the type of the content being returned? To be fair, I am pretty doubtful there is. Other ideas or alternatives are welcome. I am still actively looking for some.</p>

<p>Thanks!</p>