1

I have javascript that has a window event listener that loads a function. I would like to disable this event listener on mobile though. How can I achieve this?

window.addEventListener("load", setupMathCalculator);
penone
  • 589
  • 1
  • 6
  • 18
  • Does this answer your question? [What is the best way to detect a mobile device?](https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device) – Pac0 Aug 09 '20 at 21:09

1 Answers1

0

You can use window.matchMedia, just pass an argument with proper media query:

const media = window.matchMedia("(max-width: 700px)")
if (media.matches){
    window.addEventListener("load", setupMathCalculator);    
}