使用javascript在Chrome中检测NPAPI支持 [英] Detecting NPAPI support in Chrome using javascript
问题描述
由于Google Chrome在2015年9月后将不再支持NPAPI,有没有什么方法可以
来检测使用JavaScript在Chrome中的NPAPI支持,这样Alternative
内容将会加载或向用户显示警告消息使用旧版Chrome。
有一个由chrome 42禁用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屋!