码迷,mamicode.com
首页 > 其他好文 > 详细

检测浏览器是否安装了flash及其版本

时间:2015-07-31 14:37:57      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

检测浏览器是否安装了flash及其版本

下面是几个需要注意的点。

1、获取所有元素

  • IE:

    1. document.all
  • FireFox:

    1. document.getElementsByTagName(*)

2、检测插件是否安装(flash)

  • IE:
    1. var swf=new ActiveXObject(‘ShockwaveFlash.ShockwaveFlash‘)
  • Firefox:
    1. //navigator的首字母必须是小写,大写是不正确的
    2. var swf=navigator.plugins["Shockwave Flash"]

完整代码如下:

  1. /**
  2. * 检测浏览器是否安装了flash; 返回json,f:是否安装;v:若安装,则返回版本号
  3. * @returns {{f: number, v: number}}
  4. */
  5. function checkFlash() {
  6. var hasFlash = 0;
  7. var flashVersion = 0;
  8. var swf = null;
  9. //document.all为IE下,document.getElementsByTagName("*")为非IE
  10. if (document.all || document.getElementsByTagName("*")) {
  11. try {
  12. swf = new ActiveXObject(‘ShockwaveFlash.ShockwaveFlash‘);
  13. if (swf) {
  14. hasFlash = 1;
  15. VSwf = swf.GetVariable("$version");
  16. flashVersion = parseInt(VSwf.split(" ")[0].split(",")[0]);
  17. }
  18. }
  19. catch (e) {
  20. //catch不能做处理,而且必须要捕捉;
  21. //否则在firefox,下,ActiveXObject会出错,下面的代码不会再去执行
  22. }
  23. if (!swf){
  24. //navigator首字母必须是小写,大写是错误的
  25. if (navigator.plugins && navigator.plugins.length > 0) {
  26. var swf = navigator.plugins["Shockwave Flash"];
  27. if (swf) {
  28. hasFlash = 1;
  29. var words = swf.description.split(" ");
  30. for (var i = 0; i < words.length; i++) {
  31. if (isNaN(parseInt(words[i]))) {
  32. continue;
  33. }
  34. flashVersion = parseInt(words[i]);
  35. }
  36. }
  37. }
  38. }
  39. }
  40. return {f: hasFlash, v: flashVersion}
  41. }




检测浏览器是否安装了flash及其版本

标签:

原文地址:http://www.cnblogs.com/xiaozhi123/p/4691960.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!