PDA

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



PDA_User
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!
Mike:)

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



<script>
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}
</script>

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

Twey
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.

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

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

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

Twey
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.

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

PDA_User
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:

<script>
if(navigator.userAgent.indexOf("PPC")!=
-1){top.location.href='http://pda.whatever.com';}
</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?

Thanks!
Greetz From the Netherlands:cool:
Mike W.

Twey
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.

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

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



<?php
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.

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

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

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

Greetz Mike:)

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

Twey
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.

mburt
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 :)

Twey
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. :)