View Full Version : looking to scan browser and redirect to it's site

08-01-2006, 11:03 AM
Hello there,

I hope someone can help me.
I'm looking for a script to put in my index-file that looks at the browser of the visitor of my site and redirect it to the correct site.

I'm traying to create different websites for netscape, IE and firefox for systems as PDA, desktop and Mac.

Is there a script that can do all that??

Thanks for helping me out!:D
Greetingz from the Netherlands!

08-01-2006, 03:26 PM
First of all, Netscape and Firefox have the same appName.

var netscape="http://whatever.com"
var ie="http://whatever.com"
if (navigator.appName=="Netscape") {window.location.href=netscape}
if (navigator.appName=="Microsoft Internet Explorer") {window.location.href=ie}

Twey told me before that this was a bad idea, so take his advice.

08-01-2006, 04:26 PM
It is... a very bad idea. Redirecting for small screens (such as those seen on mobile devices) is also a pretty bad idea, but somewhat better since occasionally there genuinely is no other way to do it (such as with mobile browsers that support only cHTML). However, these browsers tend not to support Javascript either. You should use a server-side script to check the user agent and redirect based on that.

08-01-2006, 04:30 PM
I agree. :D

08-01-2006, 04:43 PM
In fact, checking the Accept: header would be even better, if cHTML has a designated MIME-type.

08-01-2006, 05:14 PM
How would you read the browser on a mobile device, if you can't use JavaScript?

08-01-2006, 05:27 PM
I repeat:
However, these browsers tend not to support Javascript either. You should use a server-side script to check the user agent and redirect based on that.

08-01-2006, 05:30 PM
Mesa stupid.

08-02-2006, 11:35 AM
Thanks for your respons!:)
Great to read that questions posted in this forum are answert!!!
(I've posted this question at other forums over a month now but no reaction!
Here...THE SAME DAY!!!!!!! WOW!!!:eek: :D )

Ill try the script out!
Yesterday after posting here I found this script:


But I have now experians with java-programming so I have no idea what it does or how to use it. Or even if it is any good!

Can someone explain it a bit to me?

Greetz From the Netherlands:cool:
Mike W.

08-02-2006, 01:27 PM
That's not Java, it's Javascript.

It's not good. Not good at all. You should follow my suggestion above.

08-02-2006, 01:43 PM
Who knows if that browser will even support JavaScript? It's not very good

08-02-2006, 01:45 PM
I think what Twey means is something like this:

if ($name = strstr ($HTTP_USER_AGENT, "MSIE")){
header("Location: http://microsoft.com");
} else {
header("Location: http://someotherplace.com"))

If you don't have PHP support in your web host then that's an exceptional case that you don't have any other choices than to use javascript.

08-02-2006, 01:45 PM
PHP would be the best approach.

08-02-2006, 02:07 PM
No, I didn't, I meant something like this:
if (stripos ($SERVER['HTTP_USER_AGENT'], 'PPC') !== false)
header('Location: http://ppc.mysite.com/');

08-07-2006, 10:40 AM
Wow..what a discussion!
Thanks for helping me out!

Greetz Mike:)

08-07-2006, 02:16 PM
There is a BIG difference between Java and JavaScript. JavaScript is easier :)

08-07-2006, 03:10 PM
OK, smart-alec, *you* try working with polymorphism and multiple inheritence in JS -.-

I've just had a nightmare of a time trying to sort some of this out.

08-07-2006, 03:15 PM
Okay.. so maybe I was wrong.. But who's to say. You can make JavaScript as hard as you want it to be :)

08-07-2006, 05:32 PM
Unfortunately, some things require the more complex approach.

Lol, I haven't slept for a couple of days, working on this script, and I come on here and see "JavaScript is easier" with a big daft grin after it :p

Seriously, though... Java is much simpler. :)