Results 1 to 5 of 5

Thread: Detect browser if Ie (internet explorer) then run script?

  1. #1
    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.

  2. #2
    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.

  3. #3
    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>

  4. #4
    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]>

  5. #5
    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>

Similar Threads

  1. Internet Explorer Script Error when printing
    By rdh2 in forum Windows Software
    Replies: 5
    Last Post: 10-07-2010, 12:54 AM
  2. Fix internet explorer script error
    By Urjita in forum Windows Software
    Replies: 3
    Last Post: 17-07-2009, 05:35 PM
  3. Replies: 3
    Last Post: 16-07-2009, 01:16 PM
  4. Internet Explorer 7 script error
    By Preetish in forum Windows Software
    Replies: 4
    Last Post: 04-03-2009, 12:32 PM
  5. Script error in Internet Explorer with MSN
    By akhtar in forum Windows Software
    Replies: 3
    Last Post: 13-12-2008, 03:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,443,369.18951 seconds with 16 queries