knowing the mime type of downloaded image

D

Dan Gelder

Hi,

When the browser downloaded an image that had the .php extension but
the header "Content-type: image/png", the browsers know how to display
it. Is there any way to use javascript in the page to find out what it
decided to do? Something like parent.myframe.mimeType?

Dan
 
T

Thomas 'PointedEars' Lahn

Dan said:
When the browser downloaded an image that had the .php extension but
the header "Content-type: image/png", the browsers know how to display
it. Is there any way to use javascript in the page to find out what it
decided to do? Something like parent.myframe.mimeType?

What would frames have to do with it? This is about an *image* resource.

Quick hack (without required feature tests):

var x = new XMLHttpRequest();
x.open("HEAD", "foo.php", false);
x.onreadystatechange = function()
{
if (x.readyState == 4 && /^0|2\d\d$/.test(x.status))
{
window.alert(x.getResponseHeader("Content-Type"));
}
};
x.send(null);

Search for "XHR" or "AJAX" for details.


PointedEars
 
D

Dan Gelder

What would frames have to do with it? This is about an *image* resource.

Quick hack (without required feature tests):

var x = new XMLHttpRequest();
x.open("HEAD", "foo.php", false);
x.onreadystatechange = function()
{
if (x.readyState == 4 && /^0|2\d\d$/.test(x.status))
{
window.alert(x.getResponseHeader("Content-Type"));
}
};
x.send(null);

Search for "XHR" or "AJAX" for details.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16

The frame was sort of unclear to you, I had written a frameset that
would show a list of files in the left frame, and whatever file you
clicked on the right. If the file turned out to be a png I wanted to
draw it against a checkerboard pattern.

Nice solution just retrieving the HEAD that way -- it might even be
cached by the browser.

Thanks!!
Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top