Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-07-2009
Member
 
Join Date: Apr 2008
Posts: 42
Detect browser if Ie (internet explorer) then run script?

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.
Reply With Quote
  #2  
Old 10-07-2009
Member
 
Join Date: Oct 2008
Posts: 86
Re: Detect browser if Ie (internet explorer) then run script?

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:

Code:
<script language="javascript">var ie = 0; </script>
<script language="vbscript">ie = 1</script>
Or you can use this code:

Code:
<script type="text/javascript">var ie = 0;</script>
<!--[if IE]>
<script type="text/javascript">ie = 1;</script>
<![endif]-->
I hope this helps you.
Reply With Quote
  #3  
Old 10-07-2009
Member
 
Join Date: Apr 2008
Posts: 61
Re: Detect browser if Ie (internet explorer) then run script?

Hey please have a look at this code:
See if this helps you here the conditional loop is been used.

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>
OR Try this:
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>
Reply With Quote
  #4  
Old 10-07-2009
Member
 
Join Date: Apr 2008
Posts: 53
Re: Detect browser if Ie (internet explorer) then run 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]>
Reply With Quote
  #5  
Old 10-07-2009
Member
 
Join Date: Apr 2008
Posts: 37
Re: Detect browser if Ie (internet explorer) then run script?

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>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Detect browser if Ie (internet explorer) then run script?"
Thread Thread Starter Forum Replies Last Post
Internet Explorer Script Error when printing rdh2 Windows Software 5 10-07-2010 12:54 AM
Fix internet explorer script error Urjita Windows Software 3 17-07-2009 05:35 PM
Internet Explorer Script Error in Office Outlook web browser guest69 Windows Software 3 16-07-2009 01:16 PM
Internet Explorer 7 script error Preetish Windows Software 4 04-03-2009 12:32 PM
Script error in Internet Explorer with MSN akhtar Windows Software 3 13-12-2008 03:22 PM


All times are GMT +5.5. The time now is 10:41 AM.