Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser Detection 1

Status
Not open for further replies.

ecannizzo

Programmer
Sep 19, 2000
213
0
0
US
How do I find out which browser a user is using and then based on that redirect them to a certain page?

Thanks!
Erica
 
Hi Erica,

the easiest thing is just:

var brows = navigator.appName;

if ("Netscape" == brows)
do whatever;
else do something else;
(It's still about 40% N'scape to 60% IE,
so I personally don't worry about the other
browsers.)

But there are more sophidticated ways to do it.
And many people do it - just have a look at some source
codes of webpages.
I'm quite new to this forum, but I'm sure anybody else
might have asked the same question before and got
better answers than this one.

By the way:
Wouldn't it be less work to find out why your pages look
different in the two browsers?
Fix this and you won't have to redirect to different pages.

regards,
buraje
 
I prefer using object detection:

if(navigator.userAgent.indexOf("Opera")>=0)
{window.location="opera.htm"}

if(document.all&&!document.getElementById){window.location="IE4.htm"}

if(!document.all&&document.getElementById){window.location="NS6.htm"}

if((document.all&&document.getElementById){window.location="ie5plus.htm"}

if(document.layers){window.location="AWFULBROWSER_goaway.htm"}

and so on... these might not be fully correct, but it shows the main idea... we needed to use the userAgent property of opera because the tricky engineers decided to make it masquerade as IE and I believe it can as NS as well... jaredn@eae.net -
 
If I wanted to say this:

if (IE5 == false) or (N6 == false)
{window.location=&quot;index.asp?SSID=&quot; + <%=request(&quot;SSID&quot;)%>}

How can I make this work, since request(&quot;SSID&quot;) is used in VBScript?

Thanks!
Erica
 
something like:

N6=IE5=false

if(document.all&&document.getElementById){IE5=true}
if(!document.all&&document.getElementById){N6=true}

if(!IE5||!N6)
{
window.location=&quot;index.asp?SSID=&quot; + <%=request(&quot;SSID&quot;)%>
}

are you sure you didn't mean not IE5 and not NS6? If so you would just change the ||'s above to &&.
jaredn@eae.net -
 
Actually my problem is sending the request variable on the URL in window.location.

I am testing to make sure they are using N6 or IE5.5...

Erica
 
How do I get something off of the querystring in Javascript?

Erica
 
to access the querystring, you use:

myquery = window.location.search

that will return something that looks like this, if the url was :

myquery = mykey1=myvalue1&mykey2=myvalue2

then you can split on the &quot;&&quot;s signs:

mypairs = myquery.split(&quot;&&quot;)

then you can split on the &quot;=&quot;

myfirstvalue = mypairs[0].split(&quot;=&quot;)[1]

jaredn@eae.net -
 
btw you may want to add this after &quot;myquery = window.location.search&quot;:

myquery = myquery.substring(1,myquer.length) jaredn@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top