0

I am running the following code:

var hasMatchMediaSupport = (typeof window.matchMedia !== 'undefined') ? !!window.matchMedia('screen').matches : false;

Is there any reason why this check would return false? This is occurring in Firefox browsers only, across a wide variety of operating systems. One relevant detail is that this code is executing inside of an ad unit, sometimes inside of HTML5 ad units.

This happens in Windows 7, Windows 8, Windows 10, Mac OS X 10.8, and several other operating systems, with versions of Firefox ranging from 36 to 41.

Edit: Found this bug report here and was able to replicate in Firefox 41 on Mac OS X 10.10 - matchMedia does not run correctly inside of hidden iframes.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265

1 Answers1

0

The bug has been fixed to now return a non-null value. For example:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<style>
 .hidden { display: none; }
</style>
 
</head>

<body>
  
<iframe class="hidden" src="data:text/html;charset=utf8;,<script>document.title = window.matchMedia('screen').matches;alert(document.title)</script>" height="200" width="200"></iframe>

</body>

</html>

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265