admin管理员组文章数量:1323330
My web application uses matchMedia
. Sometimes call of this function returns null
no matter what value is passed. It is strange but it happens not always (maybe 1 of 3 times) and only in FireFox with opened FireBug. Did anybody face with such issue ?
My web application uses matchMedia
. Sometimes call of this function returns null
no matter what value is passed. It is strange but it happens not always (maybe 1 of 3 times) and only in FireFox with opened FireBug. Did anybody face with such issue ?
3 Answers
Reset to default 8It seems that matchMedia() returns null in FF when it's called in a hidden (display: none) iframe. I've encountered this behavior when I've used jQuery UI's tabs widget, and the tab panels were iframes. My workaround was to override the jQuery UI's .ui-tabs-hide CSS class:
.ui-tabs-hide { display: block !important; position: absolute; left: -99999px; }
Matchmedia returns null in case of hidden iframe, You can use this code before accessing window.matchmedia
if(typeof window.matchMedia == 'function' && window.matchMedia!=undefined && window.matchMedia('screen and (max-width: 650px)')!=null){
//Your code goes here
}
I found I had to do this:
if (w.matchMedia == null ){
format = uformat;
} else if(w.matchMedia(qo) != null) {
if (w.matchMedia(qo).matches || w.matchMedia(q).matches ) { format = mformat; }
} else {
format = uformat;
}
本文标签: javascriptmatchMedia returns null when the FireBug is enabledStack Overflow
版权声明:本文标题:javascript - matchMedia returns null when the FireBug is enabled - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742138127a2422460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论