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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with browser detection 2

Status
Not open for further replies.

sql99

Programmer
Nov 12, 2003
83
US
Hello everyone,

Can someone please tell me how to write javascript code to detect if the user is using the IE browser? If they are, to continue w/the code. If not, to display an error message = "Your browser is not supported".

Thanks in advance for your help.

sql99
 
Hi,
Create a function using something like
this as a start:
Code:
function WhatBrowser(){
var strUA = "<%=Request.ServerVariables("HTTP_USER_AGENT") %>"
 if (strUA.indexOf("IE") > 1) {
//This means IE is the Browser
}
else {
//Put message here
}
} // end of function

Hope it helps..

[profile]
 
Thank you for your reply, Turkbear...I should have posted my current code along w/the first thread. This is basically what I have...It's just a simple html file (below)...Can you please help me redirect with my exising code? I would like for users to get routed to the page if they're using IE, otherwise, I would like a pop-up box to come up saying that their browser isn't supported. Thanks in advance for your help...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<meta HTTP-EQUIV="REFRESH" Content="0; URL=http://www.test.com/main/">
<title>Untitled</title>
</head>

<body>
<H1>If you do not get automatically routed to the page, please click <a href="
</body>
</html>
 
add this to the head of your document, and remove that <meta> tag.
Code:
<script type='text/javascript'>
if (navigator.appName.toLowerCase().indexOf("microsoft") != -1) {document.location.href="[URL unfurl="true"]http://www.test.com/main";}[/URL]
else {alert('Browser not supported');}
</script>

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
If this is a professional website you're doing, it's VERY poor practice to not write your page to support the major browsers. It's not hard to do, either, though you might have to forego some of the cutesy stuff that IE has built in. Firefox is coming on stronger all the time, so you're going to be excluding a growing share of the visitors to your site if you do this.

Lee
 
Thanks everyone for your help. I tried what eligidito suggested and it worked....There's just one more thing I'd like to ask. Is there anyway to prevent the <H1> tag from coming up for ppl who do not use IE? I would just like the pop-up window to display but not the <H1> tag. The <H1> tag is however needed for IE browsers.

Thanks again,
sql99
 
Here you go:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<script type='text/javascript'>
function isIE()
{
if (navigator.appName.toLowerCase().indexOf("microsoft") != -1) {
document.location.href = "[URL unfurl="true"]http://test.com/main";[/URL] 
return true;
}
else {alert('Browser not supported'); return false;}
}
isIE();
</script>

        <title>Untitled</title>
</head>

<body onLoad='if(isIE()){document.getElementById("hSpan").style.display="block";}'>
<H1 style="display:none" id="hSpan">If you do not get automatically routed to the page, please click <a href="[URL unfurl="true"]http://www.test.com/main/">here</a></h1>[/URL]
</body>
</html>

hope that does it

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Hi eligidito,

Thanks again for all your help. It worked!

sql99
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top