Getting header information inside JavaScript

人走茶凉 提交于 2019-12-13 05:24:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!