PDA

View Full Version : current browser detect redirect script help



brent13a
05-01-2005, 09:24 AM
I have:
www.mywebsite.com/index.html for Safari (my main browser type)
www.mywebsite.com/index2.html for MS Internet Explorer
www.mywebsite.com/index3.html for Mozilla/FireFox/Netscape

can anyone help me with a (current ver compat.) browser detect then redirect script for the corresponding pages? The weak ones I've found on the net are at least 3 or 4 years old on average and are worthless.

Will the follwoing work in my <head> how do I make it compatable with all versions? version=="all" will that work and will the script work at all itself?
thanks

<SCRIPT>
browser = navigator.appName
ver = navigator.appVersion
version = ver.substring(0,1)
if (browser=="Safari") {
if (version=="All")
document.location.href="www.mywebsite.com/index.html"
}
if (browser=="Internet Explorer") {
if (version=="All")
document.location.href="www.mywebsite.com/index3.html"
}
if (browser=="Netscape") {
if (version=="All")
document.location.href="www.mywebsite.com/index3.html"
}
if (browser=="Firefox") {
if (version=="All")
document.location.href="www.mywebsite.com/index2.html"
}
if (browser=="Mozilla") {
if (version=="All")
document.location.href="www.mywebsite.com/index2.html"
}
</SCRIPT>

mwinter
05-01-2005, 11:11 AM
I have:
www.mywebsite.com/index.html for Safari (my main browser type)
www.mywebsite.com/index2.html for MS Internet Explorer
www.mywebsite.com/index3.html for Mozilla/FireFox/NetscapeDo you mind if I ask why? I sincerely doubt that is necessary, and you're potentially creating a lot of work for yourself when it comes to maintenance. Moreover, what about the user agents you appear not to have considered, such as Opera or Konqueror?


can anyone help me with a (current ver compat.) browser detectBrowser detection is flawed and unreliable. User agents regularly misrepresent themselves to ensure that users of the software aren't discriminated against.

Browser detection should be avoided in scripting. It is generally more important to know what is supported by any particular host, rather than what that host is. The only exception is when countering known bugs that cannot be examined via feature detection, or some other direct means. However, that is rare and I've never had to do it.

Mike

brent13a
05-01-2005, 03:53 PM
Well, it's really stupid: I primarily use Safari and I build my website using a mac osx program. So on my homepage background is grey BUT on all the different browsers its rendered a slightly different grey. I also have a java applet for my front page with a background; what rgb code works for safari is too dark for IE and what rgb code works for firefox/mozilla/netscape is too dark for safari. Thats my problem: very slight cross-browser incompatablility or whatever. Hence 3 different front pages.....or four if someone were to help me with a javascript and thro in a line for Opera (I believe Safari uses Konq. in it's base).

mwinter
05-01-2005, 07:26 PM
Well, it's really stupid: I primarily use Safari and I build my website using a mac osx program. So on my homepage background is grey BUT on all the different browsers its rendered a slightly different grey.Creating several different documents is not a workable solution, and I really can't see any justification for something so trivial as minor colour differences. Choosing a colour that is acceptable, but not identical, across various platforms is.

If this colour thing is centered around this applet of yours, you are probably better off deliberately choosing a different colour that works with the rest of the colour scheme.

Mike