Powered By

Basic Scripts to find Browser Properties in Javascript

Some times we may get into a need to write browser depended scripts and Css. To handle those situations, here i have got a collection of few important and useful JavaScript functions that contribute to detection of the properties of client browser such as finding the browser type, version, OS used, monitor width , height, color resolution and so on. Using the 'navigator' object we can obtain most of the browser properties.

Here is a demo for you to find the properties list of your browser with its corresponding JavaScript functions.

DemoDownload




To view all the properties related to 'navigator' object use can use the following script.

<script type="text/javascript">
for (i in navigator)
{
document.write('<br>navigator.' + i + ' = ' + navigator[i]);
}
</script>
This small piece of information can help us a lot in most of the situations. You can use the following script to find the various browser such as Firefox, IE, Opera, Chrome, safari, and even mac system with its exact version to perform some of the browser depended functionality.

var agt=navigator.userAgent.toLowerCase();
var major=parseInt(navigator.appVersion);
var mac=(agt.indexOf("mac")!=-1);
var ff=(agt.indexOf("firefox")!=-1);
var ff0=(agt.indexOf("firefox/0.")!=-1);
var ff10=(agt.indexOf("firefox/1.0")!=-1);
var ff15=(agt.indexOf("firefox/1.5")!=-1);
var ff20=(agt.indexOf("firefox/2.0")!=-1);
var ff3up=(ff&&!ff0&&!ff10&!ff15&!ff20);
var nn=(!ff&&(agt.indexOf("mozilla")!=-1)&&(agt.indexOf("compatible")==-1));
var nn4=(nn&&(major==4));
var nn6up=(nn&&(major>=5));
var ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1));
var ie4=(ie&&(major==4)&&(agt.indexOf("msie 4")!=-1));
var ie5up=(ie&&!ie4);
var op=(agt.indexOf("opera")!=-1);
var op5=(agt.indexOf("opera 5")!=-1||agt.indexOf("opera/5")!=-1);
var op6=(agt.indexOf("opera 6")!=-1||agt.indexOf("opera/6")!=-1);
var op7up=(op&&!op5&&!op6);
Your Feedbacks are welcomed!

Related Posts by Categories