browser detection

Discussion in 'JavaScript' started by khalidfarooq, Mar 30, 2010.

  1. #1
    how to detect a user browser
     
    khalidfarooq, Mar 30, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nyu, Mar 30, 2010 IP
  3. khalidfarooq

    khalidfarooq Greenhorn

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    thnx budy i m new in web development its a big pleasure for help from you
     
    khalidfarooq, Mar 30, 2010 IP
  4. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Then check for example this link from the search result: http://www.javascriptkit.com/javatutors/navigator.shtml
    There are example codes and it's described how they work. Just copy them and then try and see how they work ;)
    As an example a simple brwoser detect function built from the examples on page i linked:

    
    <script type="text/javascript">
    function detectBrowser() {
    	var browser;
    	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Firefox/x.x or Firefox x.x (ignoring remaining digits)
    		browser = "Firefox"
    	}
    	else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
    		browser = "MSIE";
    	}
    	else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
    		browser = "Opera";
    	}
    	else {
    		browser = "Browser could not be detected!";
    	}
    	
    	return browser;
    }
    
    alert(detectBrowser());
    </script>
    
    Code (markup):
    Hope this gets you started ;)
     
    Nyu, Mar 31, 2010 IP
  5. canadianguy_001

    canadianguy_001 Peon

    Messages:
    97
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    canadianguy_001, Apr 1, 2010 IP