0

I'm a web designer who just knows enough of html and css.

Right now I'm working at home on a new web, it's quite a big proyect using responsive.

and I have spent (of course) many hours making it work for Ie8, ie9 and at least decently visible with 1e7 (ie10 was good enough).

A work mate who knows stuff as Visual basic, wrote for me this little code:

 Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    ' Para seleccionar Las CSS que tiene que utilizar el navegador
    If HttpContext.Current.Request.Browser.Browser.ToUpper = "IE" Then
        LinkCSS.Href = "~/Estilos/estilos_IE.css"
    Else
        LinkCSS.Href = "~/Estilos/estilos.css"
    End If
End Sub

which even myself can uderstand. I just use a different css sheet for ALL versions of IE insteed of the normal one for the rest of browsers.

But after upgrading to windows 8.1.. I have now IE11 and the code above doesn't work anymore (it now uses the default css sheet)

The problem is I need to work quite a few hours today as tomnorrow morning I have to show to our client the web state... in all browsers, I'm trying to phone my mate but I can't reach him (he's already out of work, and can't complain about it).

So, I really hope any of you could tell me an easy way to detect ALL ie's (including ie11) so I can keep working. I'm quite desperate.

ty in advance.

Note: Nope, I can't downgrade to ie10 (not allowed) can't downgrade to windows 8 (unless format PC which is not an option)

Alvaro Menéndez
  • 8,766
  • 3
  • 37
  • 57
  • 4
    Don't detect the browser using Code behind, use conditional statements in your markup, see this [question](http://stackoverflow.com/questions/17814486/detect-ie9-without-feature-detection) – Liam Oct 21 '13 at 15:40
  • What does `HttpContext.Current.Request.Browser.Browser` equal for IE11, I can't see them changing this – Pete Oct 21 '13 at 15:42
  • 1
    If you don't want to do as Liam said you can use `HttpContext.Current.Request.Browser.UserAgent.contains("Trident")` as the IE11 user agent is `Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv 11.0) like Gecko` – megawac Oct 21 '13 at 15:44
  • 2
    @Liam IE9 was the last browser to support Conditional Comments, they aren't supported in IE10 or newer. It would be better to figure out the actual problem with the CSS, rather than sweeping it under the rug. – cimmanon Oct 21 '13 at 15:44
  • 1
    @Pete the UA for ie11 is of different from than IE<=10 – megawac Oct 21 '13 at 15:45
  • 2
    You will really want to read this: http://stackoverflow.com/a/18872067/2424 Further, I would highly suggest you figure out why you are trying to detect different browsers to begin with. Since IE8, there are extremely few situations in which you actually need to detect the browser version as long as you have a good doctype set. – NotMe Oct 21 '13 at 15:45
  • @Pete: Read this and you'll understand why they intentionally broke this. http://msdn.microsoft.com/library/ie/hh273397.aspx – NotMe Oct 21 '13 at 15:46
  • My programming knowledge is close to zero... just enough to sometimes copy and paste lines of jquery and making it work. So as I understand what the code above is suppose to do (or it was doing fine before ie11) I can't change a comma myself without breaking it. – Alvaro Menéndez Oct 21 '13 at 15:47
  • @cimmanon, good to know. Stupid IE. Always making life difficult...I suppose the real solution is to write your css so that you don't have to do IE hacks. – Liam Oct 21 '13 at 15:47
  • thanks megawac.. I'lkl try and will tell you if working fine – Alvaro Menéndez Oct 21 '13 at 15:47
  • 2
    First things first, stop trying to do browser detection. IE11 is standards compliant, so if you're writing good code, you shouldn't need to do anything special for IE11 compared with other browsers. To tell the truth, you shouldn't even need it for IE10, or even IE9. It's been a pretty solid browser in terms of standards compliance since then. IE8 and earlier, it's a bit more forgivable, but really if you're targetting IE11 and you're doing a browser detect, then you're doing something really badly wrong. – Spudley Oct 21 '13 at 15:48
  • thanks liam... but using conditional statements will take me tons of time (I already using a lot for ie 8 and ie9) but the css main shee has +2k lines so the idea was a fast way to "fix" what was not broken this morning :) ty anyway – Alvaro Menéndez Oct 21 '13 at 15:49
  • ty for all the answers. – Alvaro Menéndez Oct 21 '13 at 15:52
  • just to explain myself a bit... the web is working perfectly fine on ie11 and ie10, and some tweaks on ie8 and ie9 (many more on ie7). THe problem is nto that it doesn't work, the problem I don't have a way to work adjusting last days work to ie7 and ie8 who use a Diferent css sheet if the code above doesn't work. english not my first lenguaje, hope I can explain mayself enough – Alvaro Menéndez Oct 21 '13 at 15:55
  • Well, I think the best way to solve it (I just thought about it).. I will take my personal laptop (windows 7), install Visual Studio, and work on it with just ie10 browser (and will neve upgrade it on that computer) – Alvaro Menéndez Oct 21 '13 at 15:57
  • @AlvaroMenéndez: I think you've explained yourself well. My feedback, at least, is hoping to let you know that something is fundamentally wrong if you are tweaking a site for individual browsers for visual issues. Which means you are doing your client a disservice by going that route. – NotMe Oct 21 '13 at 15:58

1 Answers1

1

To get past the immediate issue:

Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    ' Para seleccionar Las CSS que tiene que utilizar el navegador
    If (HttpContext.Current.Request.Browser.Browser.ToUpper = "IE") or HttpContext.Current.Request.Browser.UserAgent.contains("Trident") Then
        LinkCSS.Href = "~/Estilos/estilos_IE.css"
    Else
        LinkCSS.Href = "~/Estilos/estilos.css"
    End If
End Sub

However, I'd say you should spend some time learning what doctypes are, what things different browsers support, and actually determine why you need to do browser detection in the first place. It's unnecessary for 99% of the design work you will be performing and just complicates things needlessly.

There are certain cases of various browsers not supporting some aspects of HTML5, but these are more advanced items such drag/drop. Even then, you code for fall back when that particular feature isn't available instead of giving a completely different style sheet.

NotMe
  • 87,343
  • 27
  • 171
  • 245