使用javascript在Chrome中检测NPAPI支持 [英] Detecting NPAPI support in Chrome using javascript

查看:166
本文介绍了使用javascript在Chrome中检测NPAPI支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Google Chrome在2015年9月后将不再支持NPAPI,有没有什么方法可以
来检测使用JavaScript在Chrome中的NPAPI支持,这样Alternative
内容将会加载或向用户显示警告消息使用旧版Chrome。

解决方案

有一个由chrome 42禁用NPAPI的问题。所做的是与此类似的:(类似于)



\\(TM \)|部署)/,plugins = navigator.plugins; if(plugins.hasOwnProperty(plugin)&&&&&&&&&&&&&&&& plugins){for(插件插件){if(plugins [插件] .name)){return true;如果(chromeVersion& chromeVersion [1]){if(parseInt) (chromeVersion [1],10)> = 42&&!isJavaAvailable()){//执行chrome-no-java相关的任务console.log('Java not available');这不是一个直接的NPAPI探测器,而是一个NPAPI探测器。但可以通过改变正则表达式来重写以测试受NPAPI禁用影响的插件。正则表达式被用于某种健壮性。看看 navigator.plugins ['some-number']。names 找到要检查的内容。


As Google Chrome is dropping support for NPAPI post September 2015. Is there any way to detect the NPAPI support in chrome using JavaScript so that Alternative content will be load or show warning message to User to use an older version of Chrome.

解决方案

Had an issue created by chrome 42's disabling of NPAPI. What was done was something in the lines of this: (similar to )

function isJavaAvailable() {
  var javaRegex = /(Java)(\(TM\)| Deployment)/,
      plugins = navigator.plugins;
  if (navigator && plugins) {
    for (plugin in plugins){
      if(plugins.hasOwnProperty(plugin) &&
         javaRegex.exec(plugins[plugin].name)) {
        return true;
      }
    }
  }
  return false;
}

var chromeVersion = window.navigator.userAgent.match(/Chrome\/(\d+)\./);
if (chromeVersion && chromeVersion[1]) {
  if (parseInt(chromeVersion[1], 10) >= 42 && !isJavaAvailable()) {
    // do chrome-no-java-related task
    console.log('Java not available');
  }
}

This is not a direct "NPAPI-detector", but can be rewritten to test for the plugins affected by NPAPI disabling through changing the regex for instance. Regex was used for some kind of robustness. Had a look into navigator.plugins['some-number'].names to find what to check for.

这篇关于使用javascript在Chrome中检测NPAPI支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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