Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:02:41+00:00 2026-06-02T16:02:41+00:00

I do have a HTML5 document that uses media queries. To cater for users

  • 0

I do have a HTML5 document that uses media queries. To cater for users of older browser I was just trying to emulate the behavior in JS and use modernizr 2.5.3 (the file i got from the HTML5 Boilerplate download yesterday) to do the mq-testing.

Another thing I’d like to do is change the UI a little if the client supports touch events using simple Modernizr.touch.

I do this the following way:

//$window is $(window)
if ($window.width() < 575 || Modernizr.touch){ 
    //change UI layout a little
}

if (Modernizr.touch){ 
    //enable tap-navigation for touch devices
}

if (!Modernizr.mq('only all and (min-width: 575px)')){ //fix non-media query browsers

    $window.resize(function(){

    if ($window.width() < 575){
        //add CSS
    } else {
        //remove CSS
    }).trigger('resize');

}

This works fine in Webkit (mobile and desktop) and Firefox, yet when I try to open the page in Opera (11.6) or the Internet Explorer (7 to 9) hell breaks loose. Events will fire a random number of time, jQuery animations will stop halfway through, to be honest I have no clue what could be going on (no console errors though). When I remove the modernizr script in the head of my page, it is working just fine (except for the feature detection of course…).

What I am also doing is using the html5shiv (I’m loading this after the modernizr, yet still in the head) like:

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

I’d suspect this to be the culprit in case IE breaks, but since this should take no effect on Opera’s behavior, I am a little clueless.

Am I doing something wrong or is this some kind of bug and I should look for another way to do my feature detection?

EDIT:

While I am trying to find out what is happening I found out the following: What seems to be root of all evil is just the media query test: Modernizr.mq('only all and (min-width: 575px)'). As soon as this is called things go crazy. I can jot this into the console and will get the right result, yet it seems to break something in some weird way. Also, I can break a running page (that hasn’t called this before) by calling this from the console.

EDIT No. 2:

While searching for an alternative way to handle the feature testing I found this library over at dev.opera that (wow!) seems to work fine in Opera. Yet it does not work in IE (Webkit and Firefox are fine) as it complains about:

style.innerText = '@media ' + str + ' { #'+id+' { display:none !important; } }';

Meh.

EDIT No. 3:

So I just downgraded to modernizr 2.0.6 and things are working just fine in all browsers now. Although I’m still not sure if this is a bug or I am doing something wrong, so I’ll rather wait some time before I answer this myself.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:02:41+00:00Added an answer on June 2, 2026 at 4:02 pm

    Ok, I tried everything I could to get this to work. I made sure I had the latest release of Modernizr, I isolated all of my js and left only the bare minimum on the page, still nothing works.

    As a last resort I looked through the source code of Modernizr. In the mq method, another project is cited matchMedia. The matchMediaproject is by one of the Modernizr contributors, Paul Irish. In fact, Modernizr will call mediaMatch if it already exists on the page in place of its own Media Query test. So I downloaded matchMedia.js and added it to my project and that fixed my problem.

       //From moderizr source, remarks are my notes.
        testMediaQuery = function( mq ) {
    
       //if matchMedia or msMatchMedia return the matchMedia result, else execute modernizr code
              var matchMedia = window.matchMedia || window.msMatchMedia; 
              if ( matchMedia ) {
                return matchMedia(mq).matches;
              }
        //if mediaMatch is not found the moderizr version of this method executes...
    

    You can get matchMedia.js here, https://github.com/paulirish/matchMedia.js

    Update:
    I regenerated a custom build of 2.5.3 and it works with out matchMedia.js.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am constructing a large HTML document from fragments supplied by users that have
I am trying to write a method in Ruby that uses a here-document of
Here is what I am trying to accomplish. I have a form that uses
I have created an html document that uses javascript to connect to xml and
I have a Perl script that uses Selenium to fetch a HTML document called
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
I have a page that uses jQuery.animate to scroll the body/html of the document,
I have an HTML document that is using to embed a control. In some
Ok so i have an html document that i reference in my visual studio
I have an HTML (not XHTML) document that renders fine in Firefox 3 and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.