Safari忽略window.matchMedia [英] Safari ignore window.matchMedia

查看:126
本文介绍了Safari忽略window.matchMedia的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用window.matchMedia条件,以避免在移动设备中注入视频。 这里它说自从Safari 9(我正在测试它)后,matchMedia将顺利运行,但是我的代码完全被忽略了:

I'm using window.matchMedia conditional in order to avoid the inject of a video in mobile devices. Here it says that matchMedia is going to work smoothly since Safari 9 (I'm testing on it), but my code is completly ignored:

if ( window.matchMedia("(min-width: 1025px").matches) {
   console.log('match');

   document.addEventListener("DOMContentLoaded", function() { initialiseMediaPlayer(); }, false);

   function initialiseMediaPlayer() {

      (stuff here...)

   }

}

此代码适用于Chrome,Chromium,Firefox,IE和Edge。

This code works perfectly on Chrome, Chromium, Firefox, IE and Edge.

有没有人有一个类似的问题?

Does anyone had a similar issue?

推荐答案

问题在于格式化,奇怪的是其他浏览器修复了行为,即使它格式不正确。在1025px之后,它缺少一个额外的结束)括号。尝试:

The issue is in the formatting, oddly enough the other browsers fix the behavior even though it is malformed. It's missing an additional closing ")" parenthesis after the 1025px. Try:

if ( window.matchMedia('(min-width:1025px)').matches) {
   console.log('match');

   document.addEventListener("DOMContentLoaded", function() { initialiseMediaPlayer(); }, false);

   function initialiseMediaPlayer() {

      (stuff here...)

   }

}

这篇关于Safari忽略window.matchMedia的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆