Alex Rivera | Logout

Run javascript/jquery only on screen media, not print

Asked 2012-08-24T15:21:49.957
10

How can I run a jquery function only on @media screen?

Background:

I have a screen.css stylesheet and a print.css stylesheet. I have two javascript functions, one of which I do not want to run on the printed version want of the page.

Edit
Report

1 Answer

5

In latest browsers you can use matchesMedia:

if (window.matchMedia("screen").matches) {
    ....
}

If you want to support older browsers too you can use a polyfill like matchMedia.js

answered 2012-08-24T15:28:38.697

Your Answer