I'm making a website that contains CSS that only works in Firefox 3.5+ and Safari 4+
I would like to redirect people to my home.htm if they have either FF 3.5+ or Safari 4+.
If they have any other kind of browser or version, I would like them redirected to sorry.htm
I managed to get hold of a script that should do this, but it doesn't appear to work.
Here it is:
Code:
<script>
var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)
if (browser_type=="Firefox"&&browser_version>=3.5)
window.location.replace("home.htm")
else if (browser_type=="Safari"&&browser_version>=4)
window.location.replace("home.htm")
else
window.location="sorry.htm"
</script>
I've put this in the <head> section.
However, when I try it in my browser (Firefox 3.5.3) it takes me to sorry.htm
And when I try it in Safari 4.0.2 it also takes me to sorry.htm
How come this doesn't work? Can anybody help me with this?
I'm making a website that contains CSS that only works in Firefox 3.5+ and Safari 4+
I would like to redirect people to my home.htm if they have either FF 3.5+ or Safari 4+.
If they have any other kind of browser or version, I would like them redirected to sorry.htm
You are going about this all wrong. Javascript and redirecting is NOT the correct solution here, the solution is to fix the css (without javascript!) to work in IE as well as FF & Safari. Believe it or not, it can be done relatively easily and is not really as hard as the javascript solution.
If your really want to keep out certain browsers it would be best to do it server side... javascript can be turned off. I redirect cellphones / handhelds to special pages that way. But of course if you want everybody to see your pages, then astupidname is right... FIX the css.
Thanks for the quick replies. I want everyone to have a chance to see my site, but I would like them to know them to know that some CSS is not supported by other browsers than Firefox and safari. This is in sorry.htm, along with a "show me the website anyway"-button. I can't fix the CSS, because there are no alternatives. Believe me, I've tried.
I would like help with this script, and not tips to avoiding it.
There are ALWAYS alternatives! CSS is the answer to rendering you pages cross-browser... even if a browser doesn't support something there are usually similar acceptable solutions for troublesome browsers. And there are a lot mor browsers than just IE, Firefox and Safari.... not a good idea to check them by "name" check by name / type. I am using a dev version of Firefox... it doesn't say firefox... it says Shiretoko, but uses the Gecko engine so you have to check for the engine that is the same.
For server side browser redirection or content replacement, I use PHP
if ($o == "OTHER" && $b == "OTHER") {
echo " something for unsupported os and unsupported browser";
} else {
echo "something for everybody else ";
}
?>
This sample contains most of the options you might need... just change it to suit your needs. But remember, the User Agent string CAN be faked in various ways by the user. More info on User Agent strings.
..I want everyone to have a chance to see my site, but I would like them to know them to know that some CSS is not supported by other browsers than Firefox and safari...
Except for possibly Chrome, Opera 10, or IE 9 - which will never have a chance to run the CSS on your page because you will be re-directing them without giving them the chance.
The best way is to have a page that functions in all browsers. If a browser does not support the super cool stuff, then they'll never know it, because they will just never see it.
Bookmarks