JavaScript : Detecting the Visitor's Browser
Contents ]
Sékine Coulibaly

I'll Take You Wherever You Need to Go

With the information collected (browser name and version, plus operating system), you can direct the browser towards various pages on your site.

Imagine for instance that you wish to automatically lead visitors using the Windows, Macintosh or Unix systems towards customised content (a specific server or section of your site). All you have to do is collect the value of the Plateforme function as follows:

<script>
if (Plateforme = "Macintosh") {
this.location = "http://www.apple.com";}
if (Plateforme = "Unix") {
this.location = "http://www.ugu.com";}
if (Plateforme = "Windows") {
this.location = "http://www.microsoft.com";}
</script>

The instruction this.location can instantly connect browsers to the address specified to the right of the equals sign. It comes in handy if you put it in a conditional expression as we did here. In fact, Windows fans are directed towards Microsoft, Macintosh addicts towards Apple, and Unix aficionados towards the Unix Guru Universe. Happiness is making everyone feel at home.