0

I have a website with a few jQuery animations, commands, etc. It runs flawlessly in Google Chrome and Firefox, but is a real pain when it comes to IE.

Is there a code I can insert at the beginning of my webpage (before loading anything else) in order to check what browser the user is using, and if it's IE, get a warning box to pop up to ask him (kindly) to consider switching to FIrefox or Chrome?

INFO: I have no knowledge whatsoever in .NET, PHP, or other server-side languages (didn't really need it so far).

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
BDdL
  • 131
  • 4
  • 14
  • possible duplicate of [How can I detect the browser with PHP or JavaScript?](http://stackoverflow.com/questions/1895727/how-can-i-detect-the-browser-with-php-or-javascript) – Quentin Jun 11 '12 at 11:10
  • There are many many solutions to common cross-broswer issues. Advising user to use another browser should be the very last resort. – Beetroot-Beetroot Jun 11 '12 at 11:24
  • possible duplicate of [Detect IE version in Javascript](http://stackoverflow.com/questions/10964966/detect-ie-version-in-javascript) – Wladimir Palant Jun 11 '12 at 12:33

5 Answers5

2

Why don't you just use the IE-only IF commands (other browser treat them as comments)?:

<!--[if IE]><div id="ie-warning">Please switch browsers!</div><![endif]--> No JS needed

For versions:

<!--[if IE lte 7]>Your IE is version 7 or lower<![endif]--> (IE Less Than or Equal to 7) <!--[if IE gte 8]>Your IE is version 8 or higher<![endif]--> (IE Greater Than or Equal to 8)

Sorry if I'm missing something, but I think that will work.

Further info: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx

  • Boom! right there!! cheers! ;) Any way to completely stop loading the page if it is indeed IE?? (just stop at that gray page saying "please switch browsers"? – BDdL Jun 14 '12 at 09:00
  • in your head: `` –  Jun 15 '12 at 06:15
  • First bit redirects the page to an IE warning page, second bit hides everything to make sure they don't get a flash of any content. –  Jun 15 '12 at 06:16
  • @BDdL Forgot to at-mention your name yesterday when I posted that so will do now to make sure you see the comment. –  Jun 16 '12 at 08:16
  • ^^ I know this was ages ago, but for Googlers that found themeslves here: All you need to hide the page and redirect them is: ``. –  Nov 18 '13 at 02:45
1

You may want to look at this... http://api.jquery.com/jQuery.browser/

I have used this is some of my webpages/sites...

if (!$.browser.mozilla || jQuery.browser.msie) {

// do something....


}
Mike Sav
  • 14,805
  • 31
  • 98
  • 143
1

using jQuery.browser property

refer link

http://api.jquery.com/jQuery.browser/

sandeep patel
  • 436
  • 4
  • 16
1

If you're already using jQuery, you can use it to detect the browser while implementing jQuery.browser:

Browser info:

<script>
jQuery.each(jQuery.browser, function(i, val) {
  $("<div>" + i + " : <span>" + val + "</span>").appendTo( document.body );
});
</script>

(example taken from the manual)

Bjoern
  • 15,934
  • 4
  • 43
  • 48
  • a'ight, i see the main picture, although i am not very very proficient in jQuery. I basically insert that as the first script in my tag, and it checks it? how do i add the popping message box that asks them to change their (stupid) browser if it is indeed IE?* – BDdL Jun 11 '12 at 11:15
  • Basically yes... but its not the best style, it is merely to demonstrate how it works. You might wanna delve a bit deeper into the usage of jQuery. There is a great post on how to create popup messages with jQuere here: http://stackoverflow.com/questions/1328723/how-to-generate-a-simple-popup-using-jquery – Bjoern Jun 11 '12 at 11:20
0

It's no nice solution but you could set a variable like isIE = true with conditional comments.

Sindhara
  • 1,423
  • 13
  • 20