Skip to content Skip to sidebar Skip to footer

Getting Header Information Inside Javascript

Is there a way to get the HTTP header information of the current page in JavaScript? I am trying to get the header information of a page like referer and other headers. How can I g

Solution 1:

Use document.referrer for referrer. Use Ajax to get the rest.

functiongetHeadersAjax(url) {
   var r = GetXmlHttpObject();
   r.open('HEAD', url, false);
   r.send(null);
   return {
      status: r.status, 
      statusText: r.statusText, 
      referrer: document.referrer,
      rawheaders: r.getAllResponseHeaders()
   };
}

Solution 2:

You can use \

document.location.href

It will return the header response

Post a Comment for "Getting Header Information Inside Javascript"