2

我的网络应用程序使用matchMedia. 有时,null无论传递什么值,调用此函数都会返回。这很奇怪,但并不总是发生(可能是 3 次中的 1 次),并且仅在打开 FireBug 的 FireFox 中发生。有人遇到过这样的问题吗?

4

3 回答 3

8

似乎 matchMedia() 在隐藏(显示:无)iframe 中调用时在 FF 中返回 null。我在使用 jQuery UI 的选项卡小部件时遇到了这种行为,并且选项卡面板是 iframe。我的解决方法是覆盖 jQuery UI 的 .ui-tabs-hide CSS 类:

.ui-tabs-hide { display: block !important; position: absolute; left: -99999px; }
于 2012-09-08T12:03:38.050 回答
3

Matchmedia 在隐藏 iframe 的情况下返回 null,您可以在访问 window.matchmedia 之前使用此代码

if(typeof window.matchMedia == 'function' && window.matchMedia!=undefined && window.matchMedia('screen and (max-width: 650px)')!=null){ //Your code goes here }

于 2013-07-23T04:59:49.897 回答
0

我发现我必须这样做:

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; 
}
于 2014-03-13T17:31:10.223 回答