Ryan's District
November 22, 2008, 06:34:02 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Ryan's District Lottery: Claim your ticket or check
Jackpot details  
 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Redirection based on browser detected by JavaScript  (Read 1710 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 04, 2006, 02:57:31 AM »


Okay, now that you have learnt browser detection, we shall see how to implement it to redirect visitors to different pages depending on their browser.

<SCRIPT LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
<!--

var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
   {
   window.location="nn.html";
   }
else if (bname.search(/microsoft/i) == 0)
   {
   window.location="ie.html";
   }
else
   {
   window.location="other_browsers.html";
   }

//-->
</SCRIPT>
After assigning the browser name to bname, we search for the presence of specific words using JavaScript Regular Expressions. (JavaScript Regular expressions have been included in version 1.2 of the language and are based on those found in the Perl language. So if you were familiar with Perl, picking up the JavaScript regular expressions would be very simple).
The search() method searches for the string specified between the two forward slashes "/". The 'i' modifier makes it possible for case sensitive searches.
The JavaScript If tests whether condition is true or false. Thus, Netscape users are redirected to nn.html, Internet Explorer users to ie.html and other browsers to "other_browsers.html".
The above code has to be placed inside the HTML head. It can also be contained inside a function which can be called using the onLoad().

Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
« on: October 04, 2006, 02:57:31 AM »

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.721 seconds with 30 queries.

Google visited last this page Today at 08:04:10 AM