Sign in to follow this  
Followers 0
Protopop

Detect Internet Explorer with Javascript

8 posts in this topic

My site NimianLegends.com has not been thoroughly tested in Internet Explorer. So for the time being I detect Internet Explorer and redirect the user to another page using this method:

if(window.ActiveXObject || "ActiveXObject" in window){    // Always true if browser is Internet Explorer    window.location = 'pages/core/ie.htm';}

Works flawlessly. Except....

 

Google's spiders must use activeX because on the Google results page it always shows the ie.htm page.

 

Is there another simple, rock solid method to detect Internet Explorer in Javascript?

Share this post


Link to post
Share on other sites

I'm not sure how rock solid it is these days, but I've always detected this by searching the navigator.userAgent for the string MSIE. For example:

var isIE = (navigator.userAgent.indexOf("MSIE") != -1);
Protopop likes this

Share this post


Link to post
Share on other sites

Thanks dhaber. I've read that Microsoft intentionally broke this kind of detection in IE 11.

 

BUT...

 

Reading your suggestion it occurs to me that i can use this to detect earlier versions of IE before the change.

 

The site works almost 100% in IE 11 so i could use your code to keep out IE 9 and below, which is really what I want to do.

 

Thanks so much - sometimes marinating ideas and hearing suggestions helps come up with new views:)

Share this post


Link to post
Share on other sites

Yes MSIE is changed in IE 11. I use this:

        this.device.ie9 = /MSIE 9/i.test(navigator.userAgent);        this.device.ie10 = /MSIE 10/i.test(navigator.userAgent);        this.device.ie11 = /rv:11.0/i.test(navigator.userAgent);

Share this post


Link to post
Share on other sites

Thanks enpu - i hadnt heard about that - it sounds very clean.

For the moment ive used dhaber's suggestion. Worked great! since it doesnt work to detect IE11 that browser just passes through.

If it's IE 10 (which is also detectable by the way you suggested) it catches it and sends it through.

IE9 or less is refused:)
 

var isIE10 = false;if (navigator.userAgent.indexOf("MSIE 10") > -1) {        // this is internet explorer 10        isIE10 = true;}var isIE = (navigator.userAgent.indexOf("MSIE") != -1);if(isIE){    if(!isIE10){    window.location = 'pages/core/ie.htm';    }};

Share this post


Link to post
Share on other sites

Works flawlessly. Except....

 

Google's spiders must use activeX because on the Google results page it always shows the ie.htm page.

 

Is there another simple, rock solid method to detect Internet Explorer in Javascript?

 

It sounds like your real issue isn't IE detection, it's robot / crawler prevention?  Why not create a robots.txt with the following?

User-agent: Googlebot Disallow: /pages/core/ie.htm 

From: http://tools.seobook.com/robots-txt/

Sir_Everard likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.