0

I was having trouble getting my IE only stylesheet to load, so I settled for some IE only inline javascript.

But this isn't working either. Could someone have a look at my code and tell me what I'm doing wrong? I currently have it placed in a script tag at the end of my html document right above the my closing html tag.

Here is my code:

<script> 

if ($.browser.msie && $.browser.version < 8) {
    // IE 7 or older
    $('.sidecolor, .EDGE-15678806, .edge-wrapper').css("display", "none");
    $('.MobileBanner').css("display", "block");

} else {
    // all other browsers
    $('.sidecolor, .EDGE-15678806, .edge-wrapper').css("display", "block");
    $('.MobileBanner').css("display", "none");
}

</script>
11
  • what jQuery version you're using? Commented Oct 21, 2015 at 19:31
  • @Caio César S. Leonardi Here's my script tag for my jQuery. Is this what you meant? <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/…> Commented Oct 21, 2015 at 19:39
  • 1
    $.browser.msie && $.browser.version < 8 — Why do you need to support IE 7? It won't even run on operating systems for which vital security updates are available! Commented Oct 21, 2015 at 19:43
  • 1
    @Quentin Because my boss Commented Oct 21, 2015 at 19:44
  • Do you absolutely have to support browsers via jQuery rather than HTML conditionals? Commented Oct 21, 2015 at 19:47

1 Answer 1

2

First of all, I suggest you use this as a simple test, you can insert your code between the script tags once you see this working for you:

<!--[if lt IE 8]>
<script>
    alert("This is some version of IE, either 7 or below, so very not awesome!);
    /*Your code here*/
</script>
<!--[if (gte IE 8) | (!IE)]><!-->
<script>
    alert("This is some version of IE, either 8 or above, much better!);
    /*Your code here*/
</script>
<!--<![endif]-->

Let me know if this helped. If it did not then it could have something to do with your elements or your CSS styling and that is another question entirely.

Reference to further tests: MSDN 'About conditional comments'

Sign up to request clarification or add additional context in comments.

5 Comments

This is also a better way to add IE only stylesheets.
@AGE I updated my link with your code and added it to my head in my html. If you have another moment. Please take a look and see if you find anything out of the ordinary. It is not running the Alert in IE. portalpacific.net/test Thank you so much for the help thus far.
@VeggieBot I cannot see the conditional statement on the provided link to your website, I only see a header element with a title, a body element with an unordered list of links, the webinspector does not show any libraries being loaded from anywhere.
@AGE would you mind taking a closer look? I understand if that's asking too much but if you have a moment I could email you a link to a zip file containing the project files or post my html in as a potential answer for you to view? I gotta launch this today. Let me know. Thanks regardless!
@VeggieBot I can try to help, but you need to understand you most likely have a conflict somewhere that is not allowing you to do such a simple browser test. I suggest you debug your code first. If that is too much, you can create a new website and start to put, piece by piece, your website's code into it, testing each part one at a time. This will help if debugging is too difficult right now. Also focus on building the project with libraries first, then your images/assets, then your HTML elements one block of code at a time... that is what I would do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.