Redirect depending on browser version

D

Duncan

Hi there,

I'm developing a website that is W3C standards strict and
uses XML/XSLT/XHTML etc. As such, viewers will need to be
using a newer browser to view the pages so parsers and
the like work correctly. The only three I really want to
support are Microsoft IE 6/Netscape 7.1/Opera 7. I want
the user to go to the main page if their browser is good
enough and to a page telling them to upgrade if not. I'm
trying to use either ASP or JavaScript to do this. Would
anybody happen to have code that they use to do this
hanging around? My JavaScript is really rusty and bad,
but I know I need something like the following if using
it:

<body onload="redirectme()" style="text-align:center;">
<script type="text/javascript">
function redirectme()
{
if (navigator.appVersion.indexOf("MSIE 6"))
{
window.location="index.html"
}
else
{
window.location="notcompatible.html"
}
}
</script>
</body>

Of course, I'm missing the browser type detection (
navigator.appName.indexof() ) and any support for
Netscape or Opera. My main problems that I see are (apart
from the above resulting in an infinite loop when run)
are:

1. The values for navigator.appName.indexOf()
2. The values for navigator.appVersion.indexOf()

Thanks a lot for reading this and even more for
responding!!!

-Duncan
 
J

Jon

Hi Duncan,
you'd just need
<script type="text/javascript">
if(!document.getElementById)location.replace('Upgrade.htm')
</script>

Jon
Microsoft MVP - FP
 
D

Duncan

Sorry, I don't follow.

What is the if(!document.getElementById)location.replace
('Upgrade.htm') doing? More precisely, is this in ASP or
JavaScript and if one or the other, what exactly is each
part doing?

-Thanks, Duncan
 
D

Duncan

Ok, after some browsing around on the MSDN website and
some playing around, I came up with the source code. It
must be placed inside the HTML tag but before the HEAD
tag. It's not exactly XHTML 1.0 compliant, but it works.
Then use the onload="redirectme" event in the body tag to
execute it. Note that it only suppors, MS IE 6.0,
Netscape 7.1 and Opera 7.23.

<script type="text/javascript">
function redirectme()
{
var name = window.navigator.appName
var version = window.navigator.appVersion
var agent = window.navigator.userAgent
if (name == "Microsoft Internet Explorer" &&
(version.indexOf("MSIE 6.0") != -1) && (agent.indexOf
("Mozilla/4.0")!= -1))
{
window.location = "http://www.microsoft.com/ie"
}

else if (name == "Netscape" && (version.indexOf("5.0") !
= -1) && (agent.indexOf("Mozilla/5.0")!= -1))
{
window.location = "http://www.netscape.com"
}

else if (name == "Opera" && (version.indexOf("7.23") != -
1) && (agent.indexOf("Opera/7.23")!= -1))
{
window.location = "http://www.opera.com"
}

}
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top