Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in Safari <13 #8

Open
nickmcmillan opened this issue Jan 11, 2021 · 2 comments · May be fixed by #17
Open

Doesn't work in Safari <13 #8

nickmcmillan opened this issue Jan 11, 2021 · 2 comments · May be fixed by #17

Comments

@nickmcmillan
Copy link

First up, thanks for making this package!

I've discovered that it doesn't work in Safari 13 (and probably below): [Error] TypeError: mq.addEventListener is not a function.

Safari 13 uses an older, outdated syntax: mq.addListener(handleChange);
Whereas modern browsers use the later spec mq.addEventListener('change', handleChange);
(https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener)

You could give this a shot instead (although I haven't tested it):

try {
  mq.addEventListener('change', handleChange);
} catch (err) {
  // Safari
  mq.addListener(handleChange);
}
@LoganDark
Copy link

LoganDark commented Jun 27, 2021

if (mq.addListener) {
    mq.addListener(handleChange);
} else {
    mq.addEventListener('change', handleChange);
}

@niallpaterson niallpaterson linked a pull request Jul 5, 2021 that will close this issue
@mitchellwarr
Copy link

I'm getting a similar looking issue with Internet Explorer 11

Object doesn't support property or method 'addEventListener'

Can confirm that this PR will fix the issue as I have tested it locally and IE stops breaking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants