我的web应用程序使用matchMedia。有时,无论传递什么值,调用此函数都会返回null。这很奇怪,但它并不总是发生(可能是3次中的1次),而且只有在打开FireBug的FireFox中才会发生。有没有人遇到过这样的问题?
发布于 2012-09-08 20:03:38
在一个隐藏的(display: none) iframe中调用matchMedia()时,它似乎在FF中返回null。我在使用jQuery UI的选项卡小部件时遇到过这种行为,选项卡面板是iframes。我的解决方法是覆盖jQuery UI的.ui-tabs-hide CSS类:
.ui-tabs-hide { display: block !important; position: absolute; left: -99999px; }发布于 2013-07-23 12:59:50
如果是隐藏的iframe,则Matchmedia返回null,您可以在访问window.matchmedia之前使用此代码
if(typeof window.matchMedia == 'function' && window.matchMedia!=undefined && window.matchMedia('screen and (max-width: 650px)')!=null){ //Your code goes here }
发布于 2014-03-14 01:31:10
我发现我不得不这样做:
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;
}https://stackoverflow.com/questions/12056313
复制相似问题