Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I am making a website and I recently found out that not everything is where it is supposed to be when I view it in Internet Explorer. Where can I find a script that checks the browser and then sends it to a new web page if it is not compatible? have viewed my site in IE, FireFox, Safari, and Google Chrome; all work fine except IE.

If it's php, then something like below could be used to find ie users
if(preg_match('/msie/i', $_SERVER["HTTP_USER_AGENT"]) > 0) { header("location: some url"); } else { header("location: some other url"); }With javascript, you can use the navigator object
if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) { window.location = some url; }You need to be careful of using user agents though as they can be spoofed. What's being displayed incorrectly?

That code didn't work, it just showed the code on the
page, then I added <script type="javascript> to the
begging and </script> at the end; the code didn't show,
but it also didn't do anything.P.S. I used the javascript code and I did change the URL to where I wanted it to go.

the php version
<?php if(preg_match('/msie/i', $_SERVER["HTTP_USER_AGENT"]) > 0) { header("location: some url"); } else { header("location: some other url"); } ?> <html> ... </html>The javascript version.
<html> <head> <script language="javascript"> function myredirect() { if(navigator.userAgent.toLowerCase().indexOf("msie") != -1) { window.location = some url; } } </script> </head> <body onload="myredirect()"> ... </body> </html>Since you mentioned the code was displayed in the browser, I'm guessing you didn't place it within php tags or tried to execute the code as an html file.
the header() function must be called prior to any output displaying on the browser or it will croak perhaps with an error depending on how php is configured. You can also delay the output using php's output buffering functions if you had to.
Hope that clears up any confusion I may have caused in the first rely. If not, post away. :)

So am I supposed to put both of those into my website?
Do I save them as separate files or just put it n my *.html file?

Thank you that helped a lot, I just wasn't putting my URL in quotes which is probably why it didn't work because it works now. Thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |