How do I get this information from the client using Javascript?

How do I get this information? I am creating javascript (no jquery) that gets plugins and user agent and I want to include them as well. I prefer the client side, I know how to do it from PHP.

I saw it at http://browserspy.dk/headers.php and http://browserspy.dk/accept.php and https://panopticlick.eff.org/index.php?action=log&js=yes

enter image description here

+3


source to share


2 answers


Use this to get all http headers:



var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
var headers = req.getAllResponseHeaders().toLowerCase();
console.log(headers);

      

0


source


var readHeader = (function() {

  // Hidden cache for the headers...
  var _request = undefined;

  return function(name) {
    //
    // We have a request cached...
    ///
    if (_request) {
      return _request.getResponseHeader(name);
    }

    //
    // We need to get the request...
    //
    else {
      // Do the request and wait for it to complete.
      _request = new XMLHttpRequest();
      _request.open("HEAD", window.location, true);
      _request.send(null)
      while (_request.readyState != 4) {};

      return _request.getResponseHeader(name);
    }
  }
})();

      



You can try this thsutton code documented from the link below. https://gist.github.com/thsutton/665306

0


source







All Articles