# Navigator Object
# Get some basic browser data and return it as a JSON object
The following function can be used to get some basic information about the current browser and return it in JSON format.
function getBrowserInfo() {
var
json = "[{",
/* The array containing the browser info */
info = [
navigator.userAgent, // Get the User-agent
navigator.cookieEnabled, // Checks whether cookies are enabled in browser
navigator.appName, // Get the Name of Browser
navigator.language, // Get the Language of Browser
navigator.appVersion, // Get the Version of Browser
navigator.platform // Get the platform for which browser is compiled
],
/* The array containing the browser info names */
infoNames = [
"userAgent",
"cookiesEnabled",
"browserName",
"browserLang",
"browserVersion",
"browserPlatform"
];
/* Creating the JSON object */
for (var i = 0; i < info.length; i++) {
if (i === info.length - 1) {
json += '"' + infoNames[i] + '": "' + info[i] + '"';
}
else {
json += '"' + infoNames[i] + '": "' + info[i] + '",';
}
};
return json + "}]";
};
# Syntax
- var userAgent = navigator.userAgent; /* It can simply be assigned to a variable */
# Remarks
-
1. Internet Explorer 10 and below
1. Opera 12 and greater