Chris Burton
Chris Burton

Reputation: 1205

Detect all browsers except IE?

Is there a way to detect all browsers but IE for a redirect with either HTAccess or Javascript? Something like if not IE, redirect to site.com?

Upvotes: 0

Views: 257

Answers (4)

Ilya Kantor
Ilya Kantor

Reputation: 589

You do understand that method with conditional comments, described in the previous unswer won't work in IE10? IE10 doesn't support conditional comments and it releases soon.

So, to make your code really work, rely either on feature detection or on userAgent. But userAgent also fails sometime, when there are many plugins, so "Internet Explorer" or "MSIE" may be cut in real life.

To make the detection more reliable, throw in a bit of feature sniffing:

if ('\v'=='v' || /msie/i.test(navigator.userAgent);) {
  // ah that's you IE!
} 

That's enough.

Upvotes: 0

techfoobar
techfoobar

Reputation: 66663

I would suggest using IE's conditional comments rather since that would mean that the redirect code will not be even interpreted by IE. i.e. IE wont have run the JS code at all, only other browsers will.

Redirection using JS

<!--[if !IE]> -->
    <script>
    window.location.href = 'http://not-ie.com'
    </script>
<!-- <![endif]-->

Redirection using meta refresh

<!--[if !IE]> -->
    <meta http-equiv="refresh" content="5;url=http://not-ie.com/"> 
<!-- <![endif]-->

Technique for not showing the page before redirection

You can do this by rendering the <body> tag conditionally. Disclaimer: haven't tested this.

<!-- for non-ie browsers, render the body tag as invisible -->
<!--[if !IE]> -->
    <meta http-equiv="refresh" content="5;url=http://not-ie.com/"> 
    <body style="display: none">
<!-- <![endif]-->

<!-- for ie, render the body tag normally -->
<!--[if IE]> -->
    <body>
<!-- <![endif]-->

<!-- your page content HTML goes here -->

</body></html>

For more info on conditional comments: http://www.quirksmode.org/css/condcom.html

Upvotes: 2

Kernel James
Kernel James

Reputation: 4064

You can do:

<!--[if IE 6]><script>location.href='youhazie6.htm';</script><![endif]-->

Upvotes: 0

elclanrs
elclanrs

Reputation: 94101

var ie = /msie/i.test(navigator.userAgent);
if (!ie) { location.href = 'http://site.com'; }

Upvotes: 2

Related Questions