Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access page header of the current page in javascript [no ajax]

How can I view the page headers of the loaded page using javascript.

Is there something where I can execute a

e.g. window.pageHeaders['session']

Note: I am not talking about a Ajax page load.

like image 340
Prakash Raman Avatar asked Aug 14 '12 10:08

Prakash Raman


People also ask

Can JavaScript access response headers?

Can I read response headers in JavaScript? While you can't ready any headers of HTML response in JS, you can read Server-Timing header, and you can pass arbitrary key-value data through it.

How do I send a header in HTTP request?

To add custom headers to an HTTP request object, use the AddHeader() method. You can use this method multiple times to add multiple headers. For example: oRequest = RequestBuilder:Build('GET', oURI) :AddHeader('MyCustomHeaderName','MyCustomHeaderValue') :AddHeader('MySecondHeader','MySecondHeaderValue') :Request.


1 Answers

Check out this jsfiddle.

Linking from this question.

This answer by Raja will get the page headers for the current page.

var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
alert(headers);
like image 166
Undefined Avatar answered Sep 19 '22 15:09

Undefined