SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: if condition

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I come from a C++ background and I was wondering how you can write an if condtion in JavaScript. I want to write something like this.

    if (browser equals Internet Explorer)
    {
    load this script (http://dynamicdrive.com/dynamicindex8/autocenter.htm)
    }


    Thanks.

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Out of "Beginning JavaScript" by Paul Wilton (modified, of course):

    Code:
    <script language="JavaScript">
    
      function getBrowser() {
      var browser = navigator.appName;
    
      if (browser.indexOf("Microsoft") >= 0) {
        browser = "MSIE";
      } else if (browser.indexOf("Netscape") >= 0) {
        browser = "NN";
      } else {
        browser = "Unknown";
      }
      return browser;
      }
    
    </script>
    Just call the getBrowser() function whenever needed.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!


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
  •