0

Is there any way to get content type and content disposition of a url using java-script?

Thanks

PHCJS
  • 445
  • 4
  • 19
Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87
  • Please provide some context. – Felix Kling Dec 10 '14 at 07:30
  • 1
    If I am correct, you could use ajax to get your url, but use HEAD method, that will return to you only request headers. It's light and if server supports it, you will have your info. http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html – Beri Dec 10 '14 at 07:31

1 Answers1

0

Unfortunately, there isn't an API to give you the HTTP response headers for your initial page request.

Accessing the web page's HTTP Headers in JavaScript

Although you could make a new request and read those:

var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);
Community
  • 1
  • 1
Zymotik
  • 6,412
  • 3
  • 39
  • 48