【问题标题】:Check if pause() exists in <video> (Safari 5.1.7 on Windows - HTML5 videos)检查 <video> 中是否存在 pause()(Windows 上的 Safari 5.1.7 - HTML5 视频)
【发布时间】:2013-09-05 12:01:42
【问题描述】:

在未安装 Quicktime 时,Windows 上的 Safari 5.1.7 不支持 video 元素上的 play()pause() 等。

因此,我想检测它是否受支持。

jQuery('video').each(function(){
    this.pause();
});

返回:TypeError: 'undefined' is not a function (evaluating 'this.pause()')

jQuery('video').each(function(){
    if( <<I need a way to check if pause is in this>> ){
        this.pause();
    }
});

我正在寻找一种正确执行此操作的方法。任何帮助将不胜感激!

【问题讨论】:

    标签: javascript html video safari


    【解决方案1】:

    一些特征检测怎么样:

    if (this.pause) {
      this.pause();
    }
    

    你甚至可以测试它是否是一个函数:

    if (this.pause && Object.prototype.toString.call(this.pause) === '[object Function]') {
      this.pause();
    }
    

    【讨论】:

      【解决方案2】:
      jQuery('video').each( function () {
          if (this.pause) {  //use it as a truthy check
              this.pause();
          }
      });
      

      【讨论】:

      • 谢谢!太简单了,我在想typeofinstanceofhasPropertyin等很多方法……
      猜你喜欢
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 2013-11-14
      • 2016-02-26
      • 2011-07-08
      • 1970-01-01
      相关资源
      最近更新 更多