Calling matchMedia with empty media query fails with invalid argument in IE

230 views Asked by At

Here's the snippet that fails with "invalid argument" in IE10. Works for Chrome, FF but fails for IE. I am just debugging a js issue and came across this. I dont have any prior knowledge about matchMedia or nor i am a CSS expert. Please excuse my ignorance if any.

win.matchMedia("")
1

There are 1 answers

0
sstrudeau On

I just encountered this, as well. This is inconsistent behavior in IE10-11. My solution was to implement method in my app that first checks for an empty string before invoking matchMedia.matches() ... depending on context you might do something like:

if(meqia_query === "" || matchMedia.matches(media_query)) {
  // do your thing
}

or

function myMatchMedia(media_query) {
  return (meqia_query === "" || matchMedia.matches(media_query));
}