`
qqqckm
  • 浏览: 11572 次
  • 来自: ...
社区版块
存档分类
最新评论

Flash控件的自动激活

    博客分类:
  • WEB
阅读更多

1. 在中间加入objectSwap.js
<script src='objectSwap.js' type='text/javascript'>
2. falsh控件部分 to the object tag
具体参考见:http://blog.deconcept.com/swfobject/

object代码如下:

js 代码
  1. /* ObjectSwap - Bypasses the new ActiveX Activation requirement in Internet Explorer by swapping existing ActiveX objects on the page with the same objects. Can also be used for Flash version detection by adding the param:  
  2. <param name="flashVersion" value="8" /> to the object tag.  
  3.  
  4. Author: Karina Steffens, www.neo-archaic.net  
  5. Created: April 2006  
  6. Changes and bug fixes: May 2006  
  7. Bug fixes: June 2006  
  8. Changes: October 2006 (Included Opera9 and excluded IE5.5)  
  9. */  
  10.   
  11. //Check if the browser is InternetExplorer, and if it supports the getElementById DOM method   
  12. var ie = (document.defaultCharset && document.getElementById && !window.home);   
  13. var opera9 = false;   
  14. if (ie){   
  15.     //Check for ie 5.5 and exclude it from the script   
  16.     var ver=navigator.appVersion.split("MSIE")   
  17.     ver=parseFloat(ver[1])   
  18.     ie = (ver >=6)   
  19. }else if (navigator.userAgent.indexOf("Opera")!=-1) {   
  20.     //Check for Opera9 and include it in the ObjectSwap   
  21.     var versionindex=navigator.userAgent.indexOf("Opera")+6   
  22.     if (parseInt(navigator.userAgent.charAt(versionindex))>=9)   
  23.     opera9 = true;   
  24. }   
  25. //Perform ObjectSwap if the browser is IE or Opera (if not just check flashVersion)   
  26. var oswap = (ie || opera9)   
  27.   
  28. //Hide the object to prevent it from loading twice   
  29. if (oswap){   
  30.     document.write ("<style id='hideObject'> object{display:none;} </style>");   
  31. }   
  32.   
  33. /*Replace all flash objects on the page with the same flash object,   
  34. by rewriting the outerHTML values  
  35. This bypasses the new IE ActiveX object activation issue*/  
  36. objectSwap = function(){   
  37.     if (!document.getElementsByTagName){   
  38.         return;   
  39.     }   
  40.     //An array of ids for flash detection   
  41.     var stripQueue = [];   
  42.     //Get a list of all ActiveX objects   
  43.     var objects = document.getElementsByTagName('object');   
  44.     for (var i=0; i<objects.length; i++){              
  45.         var o = objects[i];    
  46.         var h = o.outerHTML;   
  47.         //The outer html omits the param tags, so we must retrieve and insert these separately   
  48.         var params = "";   
  49.         var hasFlash = true;   
  50.         for (var j = 0; j<o.childNodes.length; j++) {   
  51.             var p = o.childNodes[j];   
  52.             if (p.tagName == "PARAM"){   
  53.                 //Check for version first - applies to all browsers   
  54.                 //For this to work, a new param needs to be included in the object with the name "flashVersion" eg:   
  55.                 //<param name="flashVersion" value="7" />   
  56.                 if (p.name == "flashVersion"){   
  57.                     hasFlash = detectFlash(p.value);   
  58.                     if (!hasFlash){   
  59.                         //Add the objects id to the list (create a new id if there's isn't one already)   
  60.                         o.id = (o.id == "") ? ("stripFlash"+i) : o.id;   
  61.                         stripQueue.push(o.id);   
  62.                         break;   
  63.                     }   
  64.                 }    
  65.                 params += p.outerHTML;                
  66.             }   
  67.         }      
  68.         if (!hasFlash){   
  69.             continue;   
  70.         }          
  71.         //Only target internet explorer   
  72.         if (!oswap){   
  73.             continue;   
  74.         }    
  75.         //Avoid specified objects, marked with a "noswap" classname   
  76.         if (o.className.toLowerCase().indexOf ("noswap") != -1){   
  77.             continue;   
  78.         }          
  79.         //Get the tag and attributes part of the outer html of the object   
  80.         var tag = h.split(">")[0] + ">";               
  81.         //Add up the various bits that comprise the object:   
  82.         //The tag with the attributes, the params and it's inner html   
  83.         var newObject = tag + params + o.innerHTML + " </OBJECT>";     
  84.         //And rewrite the outer html of the tag    
  85.         o.outerHTML = newObject;   
  86.     }   
  87.     //Strip flash objects   
  88.     if (stripQueue.length) {   
  89.         stripFlash(stripQueue)   
  90.     }   
  91.     //Make the objects visible again   
  92.     if (oswap){   
  93.         document.getElementById("hideObject").disabled = true;   
  94.     }   
  95. }   
  96.   
  97. detectFlash = function(version){   
  98.     if(navigator.plugins && navigator.plugins.length){   
  99.         //Non-IE flash detection.   
  100.         var plugin = navigator.plugins["Shockwave Flash"];   
  101.         if (plugin == undefined){   
  102.             return false;   
  103.         }   
  104.         var ver = navigator.plugins["Shockwave Flash"].description.split(" ")[2];   
  105.         return (Number(ver) >= Number(version))   
  106.     } else if (ie && typeof (ActiveXObject) == "function"){   
  107.     //IE flash detection.   
  108.         try{   
  109.             var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);   
  110.             return true;   
  111.         }   
  112.         catch(e){   
  113.             return false;   
  114.         }   
  115.     }   
  116.     //Catchall - skip detection   
  117.     return true;   
  118. }   
  119.   
  120. //Loop through an array of ids to strip   
  121. //Replace the object by a div tag containing the same innerHTML.   
  122. //To display an alternative image, message for the user or a link to the flash installation page, place it inside the object tag.     
  123. //For the usual object/embed pairs it needs to be enclosed in comments to hide from gecko based browsers.   
  124. stripFlash = function (stripQueue){   
  125.     if (!document.createElement){   
  126.         return;   
  127.     }   
  128.     for (var i=0; i<stripQueue.length; i++){   
  129.         var o = document.getElementById(stripQueue[i]);   
  130.         var newHTML = o.innerHTML;     
  131.         //Strip the comments   
  132.         newHTML = newHTML.replace(/<!--\s/g, "");   
  133.         newHTML = newHTML.replace(/\s-->/g, "");   
  134.         //Neutralise the embed tag   
  135.         newHTML = newHTML.replace(/<embed/gi, "<span");        
  136.         //Create a new div element with properties from the object   
  137.         var d = document.createElement("div");   
  138.         d.innerHTML = newHTML;   
  139.         d.className = o.className;   
  140.         d.id = o.id;   
  141.         //And swap the object with the new div   
  142.         o.parentNode.replaceChild(d, o);   
  143.     }   
  144. }   
  145.   
  146. //Initiate the function without conflicting with the window.onload event of any preceding scripts   
  147. var tempFunc = window.onload;   
  148. window.onload = function(){   
  149.     if (typeof (tempFunc) == "function"){   
  150.         try{   
  151.             tempFunc();   
  152.         } catch(e){}   
  153.     }   
  154.     objectSwap();   
  155. }   
  156.   
分享到:
评论

相关推荐

    再谈IE中Flash控件的自动激活 ObjectWrap

    再谈IE中Flash控件的自动激活 ObjectWrap

    大名鼎鼎SWFUpload- Flash+JS 上传

     该事件在整个文件的上传过程中定期性的被Flash控件自动触发,用以帮助开发者实时更新页面UI来制作上传进度条。  注意:该事件在Linux版本的Flash Player中存在问题,目前还无法解决。  - 传入参数  file object...

    AutoPlay_Menu_Builder6.0.1328注册版

    由于某些特殊原因,滚动文本、文本框、Flash 影片、网页浏览器、媒体播放器这几个控件不能位于其它控件的后面。  您还可以使用快捷键来微调(以一个象素为单位)控件的位置和大小。方向键用来调整控件位置,而 ...

    AutoPlay_Menu_Builder5.5.0.1328注册版

    由于某些特殊原因,滚动文本、文本框、Flash 影片、网页浏览器、媒体播放器这几个控件不能位于其它控件的后面。  您还可以使用快捷键来微调(以一个象素为单位)控件的位置和大小。方向键用来调整控件位置,而 ...

    dreamweaver的各种组件

    QuickTime Object 有了这个插件,您就可以在Dreamweaver中方便地插入QuickTime文件, 程序能自动调用相关的ActiveX,就象插入flash文件一样简单。 Awbanner 插入一会定时变换图形与连结的banner, 可设定五组连结, ...

    VBA常用技巧

    190-5 少用激活或选择语句 12 技巧191 取得文件的基本名称 12 技巧192 防止用户中断代码运行 12 技巧193 加班费计算表 12 技巧194 制作发放条 12 技巧195 费用统计表 12 技巧196 职工花名册 12 技巧197 收据系统 12 ...

    VBA编程技巧大全

    190-5 少用激活或选择语句 468 技巧191 取得文件的基本名称 469 技巧192 防止用户中断代码运行 470 技巧193 加班费计算表 472 技巧194 制作发放条 498 技巧195 费用统计表 501 技巧196 职工花名册 516 技巧197 收据...

    vc++ 开发实例源码包

    FlashPlayer播放器4.0的VC++源代码 如题。 FreeBird2011最初版(模仿飞鸽,可聊天+传文件) 该实例可进行局域网的聊天、一对多、多对一、和多对多的传送和续传,理论上这是我本人的实现目的,而且目前经测试已基本...

    软件界面设计工具_3款合集

    另外,不单单在加入控件到窗体时,在改变已存在于窗体内的控件的位置或者大小时,自动对齐功能一样会生效。这样,设计者在调整控件大小或者位置时(包括控件与控件,控件与窗体边缘等的距离等情况),工作变得很简单...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -Button控件将不再自动拥有display:inline属性,如果希望两个按钮在一行显示,请为第一个按钮设置CssStyle="float:left;"属性。 -修正了弹出菜单的位置在Firefox下不正确的BUG(feedback:eroach)。 -为TriggerBox...

    ExtAspNet_v2.3.2_dll

    -Button控件将不再自动拥有display:inline属性,如果希望两个按钮在一行显示,请为第一个按钮设置CssStyle="float:left;"属性。 -修正了弹出菜单的位置在Firefox下不正确的BUG(feedback:eroach)。 -为TriggerBox...

    FlashFXP.rar绿色免安装中文版

    在每个站点选项都添加了”连接后激活同步浏览” 添加了 -approvessl 命令行参数,用于自动允许接受 SSL 证书。请谨慎使用 添加了 MLSD 支持 (机器格式目录列表) 添加了 自动/ANSI/UTF8 (iso-8859-1/Latin-1) 编码...

    超实用的jQuery代码段

    1.20 设置Flash对象的WMode窗口模式 1.21 实现类Twitter的字数限制效果 1.22 提示文本的隐藏与显示 1.23 实现文字闪烁效果 1.24 实现文字动画效果 1.25 实现文字跟随鼠标移动变化的动画效果 1.26 文本域中光标的定位...

    高通QCA9563+QCA9882+QCA8337N 官方HDK设计数据文档/含datasheet

    它包括一个MIPS 74Kc处理器,一个SGMII接口和一个外部存储器接口,用于串行Flash,DDR 1或DDR 2,UART,PCIe,两个USB 2.0主机控制器,内置的MAC/PHY和GPO可用于LED控件或其他通用接口配置。 QCA9563支持高达216 ...

    JAVA上百实例源码以及开源项目

     用JAVA开发的一个小型的目录监视系统,系统会每5秒自动扫描一次需要监视的目录,可以用来监视目录中文件大小及文件增减数目的变化。 Java日期选择控件完整源代码 14个目标文件 内容索引:JAVA源码,系统相关,日历,...

    JAVA上百实例源码以及开源项目源代码

     用JAVA开发的一个小型的目录监视系统,系统会每5秒自动扫描一次需要监视的目录,可以用来监视目录中文件大小及文件增减数目的变化。 Java日期选择控件完整源代码 14个目标文件 内容索引:JAVA源码,系统相关,日历,...

    Google Chrome 6.0.451.0 Dev 版(一个由Google公司开发的网页浏览器)

    当在窗口中激活这个功能时“任何发生在这个窗口中的事情都不会进入你的计算机。”  多进程(Multiprocessing)  能容许多个程序同时执行而互不影响,每个网页标签将位于程序窗口的外沿单独存在,当资源过高或崩溃...

    电脑问题大搜捕

    21)Macromed(用于在线播放 Flash 的控件,) 22)Microsoft 23)MsDtc(这个文件夹包含了与Microsoft Distributed Transaction Coordinator(分布式事务 协调器) 相关的文件, 分布式事务协调器可用于控制不同...

Global site tag (gtag.js) - Google Analytics