This translation is incomplete. Please help translate this article from English

El método addListener() de la interfaz MediaQueryList añade un escucha al MediaQueryListener que ejecutará una función de devolución de llamada personalizada en respuesta al cambio de estado de consulta de medios.

Esto es básicamente un alias para EventTarget.addEventListener(), para propósitos de compatibilidad con versiones anteriores: en los navegadores antiguos se puede usar addEventListener.




A function or function reference representing the callback function you want to run when the media query status changes. In the original implementation, the callback was a non-standard MediaQueryListListener object. In the new implementation the standard event mechanism is used, the callback is a standard function, and the event object is a MediaQueryListEvent, which inherits from Event.

Return value



var mql = window.matchMedia('(max-width: 600px)');

function screenTest(e) {
  if (e.matches) {
    /* the viewport is 600 pixels wide or less */
    para.textContent = 'This is a narrow screen — less than 600px wide.'; = 'red';
  } else {
    /* the viewport is more than than 600 pixels wide */
    para.textContent = 'This is a wide screen — more than 600px wide.'; = 'blue';



Specification Status Comment
CSS Object Model (CSSOM) View Module
La definición de 'addListener' en esta especificación.
Working Draft Initial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 9 (Yes) 6.0 (6.0) 10 12.1 5
New version spec update (Yes) ? 55 (55) Sin soporte (Yes) ?
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? (Yes) ? ? ? ? ?
New version spec update Sin soporte ? 55.0 (55) Sin soporte (Yes) ? (Yes)

See also