网页中Flash激活限制的处理方法

时间:2008-09-08 10:21:35 魔新豆网
本文对比了国内门户网站对网页中Flash激活限制的处理方法和技巧。
今年年初之时,微软发布了一个针对ActiveX控件的补丁,安装此补丁后的IE6中,当ActiveX控件获得焦点时,IE自动为其套上一个虚线矩形边框,并提示用户按下回车或者空格键以激活控件。刚刚正式发布中文版的IE7也是同样的处理。
最受影响的想必就是Flash控件了。当时我认为这对广告满屏飞的门户网站来说一定是个坏消息。不过微软也没有把事做绝,留了一条脚本方式解决的后路。
今天突然产生兴趣,想看看这些门户们如何应对此限制的。一番比较下来,给大家汇报一下:
新浪
首先在HTML的<head>中加载一个脚本:
<script type="text/javascript" src="http://image2.sina.com.cn/home/sinaflash.js"></script>
通过如下脚本在HTML中写入Flash广告:
<script type="text/javascript">
var objFlash = new sinaFlash("http://ad4.sina.com.cn/200611/17/73696_gundong.swf", "", "279", "56", "7", "", false,"high");
objFlash.addParam("wmode", "opaque");
objFlash.write("flashcontent_02AE4A");
</script>
下载sinaflash.js来看,其实正是 Adobe 建议使用的SWFObject。参阅Adobe的文章 JavaScript Flash Player Detection and Embedding with SWFObject。Adobe还提供了一套另外的解决方案,并集成到Dreamweaver 中,不过好像用的人不多。
新浪将其改头换面,或许加入了一些自己的处理,我没有兴趣去弄清楚:)。但我想虽然人家是MIT License,但版权信息还是不要去掉为好。
搜狐
搜狐的手段和新浪如出一辙,首先加载:
<script src="http://www.sohu.com/sohuflash_1.js" type=text/javascript></script>
调用:
var sohuFlash2 = new sohuFlash("http://images.sohu.com/cs/button/lexus/4501051127.swf", "_bflexO", "450", "105", "7");
sohuFlash2.addParam("quality", "high");
sohuFlash2.addParam("wmode", "Opaque");
sohuFlash2.addVariable("clickthru","http://adc.go.sohu.com/200611/10083225efd048d2153be48383171872.php");
sohuFlash2.write("_turnAD9");
sohuflash_1.js 同样改写自SWFObject,而且改得更面目全非。没必要吧,同学。
你说是搜狐抄的新浪,还是新浪抄的搜狐?
网易
网易就是不一样,处理手段显得很有技术性。首先加载脚本:
<script src="/DartRichMedia_1_03.js"></script>
页面上直接用 docuemnt.write 写入 Flash 的HTML代码。
按照微软的说明,直接在页面上使用docuemnt.write写入是不能饶开激活限制的,Hack就是那个加载的js中。代码如下:
if(typeof(dclk_isDartRichMediaLoaded) == "undefined") {
dclk_isDartRichMediaLoaded = true;
function dclkWrite(str){
if(dclk_shouldOverride) {
dclk_original_documentWrite(str);
}
else{
document.write(str);
}
}
function dclkWriteln(str){
if(dclk_shouldOverride) {
dclk_original_documentWriteLn(str);
}
else{
document.writeln(str);
}
}
function dclk_isInternetExplorer() {
return (navigator.appVersion.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") < 0);
}
dclk_shouldOverride = dclk_isInternetExplorer();
if(dclk_shouldOverride) {
dclk_original_documentWrite = document.write;
dclk_original_documentWriteLn = document.writeln;
document.write = dclkWrite;
document.writeln = dclkWriteln;
}
}
用这么迂回的方式覆盖JS默认的document.write就可以饶开激活限制?是不是有点诡异?希望网易的工程师能给大家解读一下。
雅虎中国
Yahoo!中国对Flash的处理中规中距,就是微软文章中说明的,使用一个外连的js文件,在js中用docuemnt.write 写入。
腾讯
默认Flash并没有激活! 后来者虽然气势逼人,但毕竟还需要时间打磨:)。
稍做总结吧,新浪/搜狐使用的SWFObject实际原理是在外连的JS中用innerHTML间接导入Flash代码。这和Yahoo!中国的处理方式归根揭底都基于微软的说明。
使用 SWFObject 还能解决XHTML校验的问题,不过我想门户们都还不会太在意这个:)。
网易的方式比较邪门,很有骇客色彩。不过还有比它更邪门的方式:
//只要在 </body> 后面加上一行
<script src="javascript:'document.body.innerHTML =''';"></script>
真的有效呢! (在我的IE7中无效)
本文标签: