网页中Flash激活限制的处理方法
来源:Ajax中国 发布日期:2009-09-05
本文对比了国内门户网站对网页中Flash激活限制的处理方法和技巧。今年年初之时,微软发布了一个针对ActiveX控件的补丁,安装此补丁后的IE6中,当ActiveX控件获得焦点时,IE自动为其套上一个虚线矩形边框,并提示用户按下回车或者空格键以激活控件。刚刚正式发布中文版的IE7也是同样的处理。
最受影响的想必就是Flash控件了。当时对于广告满屏飞的门户网站来说这是个坏消息。不过微软也没有把事做绝,留了一条脚本方式解决的后路。
新浪
首先在HTML的中加载一个脚本:
《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中,不过好像用的人不多。
搜狐
搜狐的手段和新浪如出一辙,首先加载:
《script src=’http://www.sohu.com/sohuflash_1.js’ type=text/javascript》《/script》
调用:
var sohuFlash2 = new sohuFlash(’/u/info_img/2008-03/05/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’);
网易
处理手段显得很有技术性。首先加载脚本:
《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);
Webjx.Com
}
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校验的问题。
网易的方式比较邪门,很有骇客色彩。不过还有比它更邪门的方式:
//只要在 后面加上一行
《script src=’javascript:’document.body.innerHTML =’’’;’》《/script》