Hi,
Is there any way to detect the client browser?
I mean I want to run a particular script if the browser is Ie (Internet explorer).
Is this possible to detect the browser? I mean if its Ie 6 or ie 7?
Thanks in advance.
Hi,
Is there any way to detect the client browser?
I mean I want to run a particular script if the browser is Ie (Internet explorer).
Is this possible to detect the browser? I mean if its Ie 6 or ie 7?
Thanks in advance.
The trick is useful in case of Internet explorer is that only Internet Explorer can run VBScript.
Now to identify if the browser id Ie or not?
We can use:
Or you can use this code:Code:<script language="javascript">var ie = 0; </script> <script language="vbscript">ie = 1</script>
I hope this helps you.Code:<script type="text/javascript">var ie = 0;</script> <!--[if IE]> <script type="text/javascript">ie = 1;</script> <![endif]-->
Hey please have a look at this code:
See if this helps you here the conditional loop is been used.
OR Try this:Code:<html> <head><title>Sample</title> <!--[if IE]> <script type="text/javascript"> alert('Place your browser related message here.'); </script> <![endif]--> </head> <body> <!--[if ! IE]><!--> <h1>This is never rendered by IE for windows</h1> <p>here goes your text</p> <!--<![endif]--> </body> </html>
Code:<SCRIPT LANGUAGE = "JavaScript"> <!-- var browser = ''; var version = ''; var entrance = ''; var cond = ''; // BROWSER? if (browser == ''){ if (navigator.appName.indexOf('Microsoft') != -1) browser = 'IE' else if (navigator.appName.indexOf('Netscape') != -1) browser = 'Netscape' else browser = 'IE'; } if (version == ''){ version= navigator.appVersion; paren = version.indexOf('('); whole_version = navigator.appVersion.substring(0,paren-1); version = parseInt(whole_version); } if (browser == 'IE' && version >= 4) document.write('<'+'link rel="stylesheet" href="ie.css" />'); if (browser == 'Netscape' && version >= 2.02) document.write('<'+'link rel="stylesheet" href="nn.css" />'); // --> </SCRIPT>
Detecting Internet Explorer More Effectively
If you are specifically interested in Internet Explorer, conditional comments might be a more appropriate choice. The following example shows an effective way to use conditional comments to display custom content.
Code:<!--[if gte IE 8]> <p>You're using a recent version of Internet Explorer.</p> <![endif]--> <!--[if lt IE 7]> <p>Hm. You should upgrade your copy of Internet Explorer.</p> <![endif]--> <![if !IE]> <p>You're not using Internet Explorer.</p> <![endif]>
Browser Detection
JavaScript includes an object called the Navigator object, that can be used for this purpose. The Navigator object contains information about the visitor's browser name, version, and more.
The Navigator Object
look at two properties of the Navigator object:
Code:<html> <body> <script type="text/javascript"> var browser=navigator.appName; var b_version=navigator.appVersion; var version=parseFloat(b_version); document.write("Browser name: "+ browser); document.write("<br />"); document.write("Browser version: "+ version); </script> </body> </html>
Bookmarks