Solved Browser Compatibility

April 6, 2009 at 23:12:45
Specs: Windows Vista, 2GB
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.

See More: Browser Compatibility

Report •


#1
April 7, 2009 at 02:13:54
✔ Best Answer
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?


Report •

#2
April 7, 2009 at 15:34:35
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.


Report •

#3
April 7, 2009 at 19:58:15
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. :)


Report •

Related Solutions

#4
April 7, 2009 at 20:13:53
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?

Report •

#5
April 8, 2009 at 00:00:33
You wouldn't need both.

If you're saving your pages as *.html, then go with the javascript version.


Report •

#6
April 8, 2009 at 19:49:27
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.

Report •


Ask Question