5

Possible Duplicate:
Accessing HTTP Headers in Javascript?

I want know a mime-type or content-type of current loaded page via JavaScript. the thing I wanna do is to check whether it is rss or html of the page.

The only thing I could find is 'document.contentType', but it is supported in Gecko ( firefox ).

does anyone know how to do it via JavaScript ?

Community
  • 1
  • 1
Shukelton
  • 71
  • 1
  • 8
  • 3
    FWIW, currently `document.contentType` does seem to be supported by Chrome, Firefox and Edge, on Windows at least. – MSpreij Oct 26 '18 at 09:30

1 Answers1

2

Use an XHR request.

var xhr = new XMLHttpRequest();
xhr.open('GET', document.location, false);
xhr.send(null);

alert(xhr.getResponseHeader("content-type"));​ // content-type
  1. Initialise the request
  2. Send the request
  3. Get the desired header using ref.getResponseHeader()

Also check out the links below.

Community
  • 1
  • 1
jeremy
  • 9,965
  • 4
  • 39
  • 59