问题
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 get those values in a JavaScript function so that I can send that information to a Java applet? The problem while I am making an Ajax call and getting header information is the referer will change to current page than the original referer.
回答1:
Use document.referrer for referrer. Use Ajax to get the rest.
function getHeadersAjax(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()
};
}
回答2:
You can use \
document.location.href
It will return the header response
来源:https://stackoverflow.com/questions/9357941/getting-header-information-inside-javascript