Home arrow Tutorials arrow Detecting a particular browser

Web Development

Welcome to Web Development section. Please choose a category. 
 
  • Hrvatski tutorijali
    Ovdje su objavljeni razni tutorijali na hrvatskom jeziku na temu PC, programiranje, web development, savjeti, trikovi, optreba racunala itd.
  • Tips / Tricks
    Articles about various tips and tricks concerning Windows, Linux and other OS usage.
  • JavaScripts
    Code snippets, tutorials and tricks for JavaScrip language.
  • PHP & MySQL
    Tutorials, code examples, tips and tricks for PHP and MySQL development.
  • Tutorials
    Place for tutorials about using various application in best and simplest way.
Detecting a particular browser Print E-mail
(1 vote)

Detecting a particular browser
Sunday, 17 June 2007

Our next example shows you how to detect a particular browser. As mentioned earlier, this is useful because you could have a page that supports JavaScript for only Netscape 3.0, therefore, you don't want a visitor to visit the page without that browser.

Detecting the appropriate browser

<HTML>
<TITLE>Detecting User's Browser</TITLE>
<HEAD></HEAD>
<BODY BGCOLOR=ffffff>
<SCRIPT Language="JavaScript">
if (navigator.appName == "Netscape"){
if (navigator.appVersion.substring(0, 3) == "3.0"){
if (navigator.appVersion.substring(3, 4) == "b"){
alert('You are using :' + navigator.appName + ' (' +
navigator.appCodeName + ') ' + navigator.appVersion +
'\nSorry! You are not using Netscape 3.0+');
history.back();
}
}
}
else {
alert('Sorry! You are not using Netscape 3.0+');
}
</SCRIPT>
</BODY>
</HTML>

Here we use the some of the properties of the Navigator object. First we find out if the browser is a Netscape browser. If so, we detect if the version is 3.0. If the version is a beta version, we display the whole browser information with its platform, and alert the user that he or she is not using a Netscape 3.0 browser.

Notice that before we closed the if statement, we used the history.back() statement. It is used so that when the user presses OK on the alert message box, the document automatically takes the user to the previous page. This is useful because sometimes if you run JavaScript 1.1 on Netscape browser 2.0 or earlier, the browser might crash; this will prevent users from crashing their browsers.

Here's another useful tip: You can send the user to a different page if the browser isn't Version 3.0. Instead of the history.back() statement, you need to type the following statement: window.location="myotherpage.html".

This script can also alert visitors that if they want to view this page, they need to acquire the appropriate browser.

Alert: The else statement is not effective unless you use a JavaScript-enabled browser besides Netscape, such as Microsoft's Explorer 3.0.

 
< Prev   Next >
What's your favorite Internet browser?
 

Login






Lost Password?
No account yet? Register

Tools

Coming soon...

Partners

Syndicate