Monday 24 February 2014

Basic of Browsers

Bowsers : It signifies the webpage.A platform where webpage loads
               there are many different types of browser available with some different
               and its unique capability
               It is important to understand the differences between different browsers
               in order to handle them in the way we expected. So it is important
               to know which browser your Web page is running in.

To get information about the browser your Web page is currently running in,
use the built-in navigator object.

Navigator Properties:
There are several Navigator related properties that you can use in your
Web page. The following is a list of the names and descriptions of each:

Property                                                       Description

appCodeName  - contains the code name of the browser, Netscape for Netscape
                               and Microsoft Internet Explorer for Internet Explorer.
appVersion   -    contains the version of the browser as well as other useful information such as
                                its language and compatibility.
language     - contains the two-letter abbreviation for the language that is used by
                        the browser. Netscape only.
mimTypes[]   - This property is an array that contains all MIME types supported by
                        the client. Netscape only.
platform[]   - contains the platform for which the browser was compiled. "Win32" for 32-bit Windows                               operating systems
plugins[]    - It is an array containing all the plug-ins that
                       have been installed on the client. Netscape only.
userAgent[]  - contains the code name and version of the browser.
                         This value is sent to the originating server to identify the client

Example :

<html>
<head>
<title>Browser Detection Example</title>
</head>
<body>
<script type="text/javascript">

var userAgent   = navigator.userAgent;
var opera       = (userAgent.indexOf('Opera') != -1);
var ie          = (userAgent.indexOf('MSIE') != -1);
var gecko       = (userAgent.indexOf('Gecko') != -1);
var netscape    = (userAgent.indexOf('Mozilla') != -1);
var version     = navigator.appVersion;

if (opera){
  document.write("its Opera ");

}else if (gecko){
  document.write("its Mozilla");

}else if (ie){
  document.write("its IE ");

}else if (netscape){
  document.write("its Netscape");

}else{
  document.write("Unknown browser");
}

document.write("<br /> Browser version info : " + version );

</script>
</body>
</html>
NOTE : you can type and test code in console (press F12) and check the navigator.useragent

No comments:

Post a Comment