-2

I want to check for IE and ask user to change brouser. I tried:

<!--[if IE]>
<p>rrff</p>
<script type="text/javascript">
alertify.alert("Please change your brouser");
</script>
<![endif]-->
<!--[if gte IE 8]>
<script type="text/javascript">
alertify.alert("Message");
</script>
<![endif]-->

<!--[if lt IE 7]>
<script type="text/javascript">
alertify.alert("Message");
</script>
<![endif]-->

(took it from Microsoft - http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx) But it show no result, except of termination of IE in two cases :)

How to check for IE and all related brousers to it? Too many functions fail here....

Tigran
  • 984
  • 2
  • 12
  • 27
  • use uncle google there is HUGE amount of information about that. – Szymon Dec 14 '13 at 12:24
  • 1
    something wrong with your code if `too many functions fail`...use feature detection – charlietfl Dec 14 '13 at 12:28
  • 1
    What @SzymonDziewoński says. Also, the article itself states `Note As of December 2011, this topic has been archived and is no longer actively maintained.` which explains why it may have issues with more recent browsers – fvu Dec 14 '13 at 12:28
  • Do you calling `alertify` script before this? Did you try just `` – mdesdev Dec 14 '13 at 12:45
  • This is good idea, but it do not work. (I mean – Tigran Dec 14 '13 at 14:20
  • There are `ScriptEngine` functions in all IE versions. Please see more details on [this SO answer.](http://stackoverflow.com/a/19570684/1169519). – Teemu Dec 15 '13 at 10:56

3 Answers3

1

Ok I'll be good friend and tell you something about IE

1. Plugin

If you want just change some elements with changing class here's plugin http://rafael.adm.br/css_browser_selector/ which is great.

How it is work , for example add before element in css class like .ie8 #something and it will work in IE8 ONLY

NOTE: dont forget use jQuery library

2. jQuery

Detecting IE using jQuery There is so many links, type in google "IE detection jquery" or something like that

HINT: before 1.9 jQuery detection was different but later 1.10 when use jQuery migrate you can still use those commands

3. CSS

http://www.quirksmode.org/css/condcom.html

I think thats all in 5 min , and when you spent some time you will learn all about that problem :)

Community
  • 1
  • 1
Szymon
  • 1,254
  • 19
  • 34
1

Alright, so whatever you are using is called Conditional Comment and this works fine. if you just want to check for IE for any version, you can do it like:

<!--[if IE]>
<script type="text/javascript">
    alertify.alert("Please change your browser");
</script>
<![endif]-->

and if want to check for some particular version, then you can do it like:

<!--[if IE 6]>
<![endif]-->

or

<!--[if lte IE 7]>
<![endif]-->

and apart of it, you can check it in JavaScript itself, like:

<script type="text/javascript">
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
    alertify.alert("Please change your browser");
}
</script>

But use any one of them, not all. Good luck!!

Ashish Kumar
  • 2,870
  • 2
  • 15
  • 26
0

You should not browser sniff. Instead do feature detection like the following:

        <script>

    if (!('querySelector' in document)  //this should work in ie 9+
         || !('localStorage' in window)  //ie 8+
         || !('addEventListener' in window)  //ie 8 + (I think)
        || !('matchMedia' in window)) {//ie 10+

        //do something here
    }

</script>
Chris Love
  • 3,312
  • 1
  • 17
  • 14