Before explaining the article, I would like to thank all readers who read my article and voted for it. Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions. Now I won't waste your time and come back to the topic. I have written this article on ‘Browser Detection’. Sometimes it can be very useful to detect the visitor's browser, and then serve up the appropriate information.
So, sometimes it can be very useful to detect the visitor's browser, and then serve up the appropriate information.
The best way to do this is to make your web pages smart enough to look one way to some browsers and another way to other browsers.
The Navigator object contains information about the visitor's browser name, version, and more.
The Navigator Object
• appName - holds the name of the browser
• appVersion - holds, among other things, the version of the browser
document.write("Browser name: "+ browser);
document.write("Browser version: "+ version);
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
The appVersion property in the example above returns a string that contains much more information than just the version number, but for now we are only interested in the version number. To pull the version number out of the string we are using a function called parseFloat(), which pulls the first thing that looks like a decimal number out of a string and returns it.
The example below displays a different alert, depending on the visitor's browser:
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")
alert("Your browser is good enough!");
alert("It's time to upgrade your browser!");