代码之家  ›  专栏  ›  技术社区  ›  Code Guy

正在检查浏览器中是否支持BroadcastChannel API?[副本]

  •  0
  • Code Guy  · 技术社区  · 4 年前

    我有一个例子,我需要检查Safari V 5.1是否支持 FileReader 作用我尝试过:

    if (typeof FileReader !== "object") { 
        alert("NA");
    }
    

    然而,现在即使在我的其他浏览器中,我也知道它们支持 字符流 我显示了警报!所以我想我一定做错了什么。

    0 回复  |  直到 11 年前
        1
  •  13
  •   Michael    11 年前

    检查是否定义了函数:

    你试过下面的吗?

    if(typeof(window.FileReader)!="undefined"){
         //Your code if supported
    }else{
         //your code if not supported
    }
    
        2
  •  3
  •   Umair Khan    5 年前

    从…起 MDN

    window对象的window属性指向窗口对象本身。

    JS IN 可以使用运算符。

    if('FileReader' in window)
      console.log('FileReader found');
    else
      console.log('FileReader not found');

    或使用给定的代码示例。

    if (!'FileReader' in window) {
      alert("NA"); // alert will show if 'FileReader' does not exists in 'window'
    }