Computing.Net > Forums > Web Development > Browser Compatibility

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Browser Compatibility

Reply to Message Icon

Name: You know who we are.
Date: April 6, 2009 at 23:12:45 Pacific
OS: Windows Vista
CPU/Ram: 2GB
Product: Microsoft / Vista
Subcategory: Javascript/Ajax
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: April 7, 2009 at 02:13:54 Pacific
Reply:

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?


0

Response Number 2
Name: You know who we are.
Date: April 7, 2009 at 15:34:35 Pacific
Reply:

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.


0

Response Number 3
Name: shutat
Date: April 7, 2009 at 19:58:15 Pacific
Reply:

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


0

Response Number 4
Name: You know who we are.
Date: April 7, 2009 at 20:13:53 Pacific
Reply:

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?


0

Response Number 5
Name: shutat
Date: April 8, 2009 at 00:00:33 Pacific
Reply:

You wouldn't need both.

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


0

Related Posts

See More



Response Number 6
Name: You know who we are.
Date: April 8, 2009 at 19:49:27 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Browser Compatibility

Browser compatibility www.computing.net/answers/webdevel/browser-compatibility/2371.html

Browser Compatibility www.computing.net/answers/webdevel/browser-compatibility/2721.html

Redundant Information www.computing.net/answers/webdevel/redundant-information/2015.html