支持IE、Firefox、Opera的对联广告(来自网易)
我以前在网上找的那个对联代码,也不错,但就是不支持firefox和opera。今天在查看了一下网易的主页源代码。把下面这段代码和大家分项一下。这个代码不错,但是有两个缺点。其一,是对联广告不支持随鼠标滚动,第二是,代码flash背景不是透明的。
透明好处理,把代码中的“opaque” 替换成“transparent”,我以为就可以了,但结果却是ie透明了,firefox不显示了,firefox透明,ie却不透明了。
/*
*表示必须,非必须项的第一个选项选项为默认选项
url(*) Flash地址
id(*) 对联的ID,保持唯一,建议用nad+合同号+位置的形式,如:nad5694HomeLeft
width:110/任意数字 宽度
height:260/任意数字 高度
x:left/right 水平位置
xPx:0/任意数字 水平方向上Logo左边(右边)到浏览窗口左边(右边)的像素值
yPx:110/任意数字 垂直方向上Logo顶边(底边)到浏览窗口顶边(底边)的像素值
operaShow:true/false 因为Opera目前不支持as和js通信,可以Opera下对联无法关闭,可以通过false来设置Opera下对联不显示
*/
var nadCouplet = function(url,id,options){
if(window.screen.width<1024){return;}
if(nadIsLtIE5_5()){return;}
if(!url){return;}else{this.url = url;}
if(!id){return;}else{this.id = id;}
this.options = {
width: 110,
height: 260,
x: 'left',
xPx: 0,
yPx: 110,
operaShow: true
}
Object.nadExtend(this.options,options||{});
if(!this.options.operaShow && nadIsOpera){return;}
this.create();
}
nadCouplet.prototype={
create:function(){
var wrap = document.createElement('span');
var _opt = this.options;
var _x = _opt.x;
var _id = this.id
var id = _id + _x;
if(_x=='left'){_id += 'right';}
else{_id += 'left';}
wrap.style.position = 'absolute';
wrap.innerHTML = nadCreateSwfHtml(this.url,id,{
width : _opt.width,
height : _opt.height,
quality : 'high',
wmode : 'window'
});
wrap.style[_opt.x] = _opt.xPx + 'px';
wrap.style.top = _opt.yPx + 'px';
document.getElementById("ssid1").appendChild(wrap);
this.ad = wrap;
this.initScrollTop = 0;
var _fscHtml ='';
_fscHtml += '<script type="text/javascript">';
_fscHtml += 'function '+ id +'_DoFSCommand(command,args){'
_fscHtml += 'if (command == "quit"){'
_fscHtml += 'document.getElementById("'+ id +'").parentNode.style.visibility = "hidden";';
_fscHtml += 'if(document.getElementById("'+ _id +'")){document.getElementById("'+ _id +'").parentNode.style.visibility = "hidden";}';
_fscHtml += '}}';
_fscHtml += '<\/script>';
if(nadIsIE){
_fscHtml += '<script type="text/javascript" for="'+ id +'" event="FSCommand(command,args)">';
_fscHtml += id + '_DoFSCommand(command,args)';
_fscHtml += '<\/script>';
}
document.write(_fscHtml);
}
}
/*==common function==*/
var nadUserAgent = navigator.userAgent;
var nadIsOpera = nadUserAgent.indexOf('Opera')>-1
var nadIsIE = nadUserAgent.indexOf('MSIE')>-1 && !nadIsOpera;
var nadIsLtIE5_5 = function(){
if(nadIsIE){
var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
reIE.test(nadUserAgent);
var IeVersion = parseFloat(RegExp["$1"]);
return IeVersion <5.5;
}
}
Object.nadExtend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var nadCreateSwfHtml = function(url,id,options){
var swfHtml='';
if(!url){return;}
_opt = options;
if(nadIsIE){
swfHtml += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ _opt.width +'" height="'+ _opt.height +'" id="'+ id +'">';
swfHtml += '<param name="movie" value="'+ url +'" />';
swfHtml += '<param name="allowScriptAccess" value="always" />';
swfHtml += '<param name="quality" value="'+ _opt.quality +'" />';
swfHtml += '<param name="wmode" value="opaque" />';
swfHtml += '</object>';
}
else{
swfHtml += '<embed src="'+ url +'" quality="'+ _opt.quality +'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ _opt.width +'" height="'+ _opt.height +'" wmode="opaque" id="'+ id +'" name="'+ id +'" swliveconnect="true"></embed>'
}
return swfHtml;
}
/*==common function==*/
*表示必须,非必须项的第一个选项选项为默认选项
url(*) Flash地址
id(*) 对联的ID,保持唯一,建议用nad+合同号+位置的形式,如:nad5694HomeLeft
width:110/任意数字 宽度
height:260/任意数字 高度
x:left/right 水平位置
xPx:0/任意数字 水平方向上Logo左边(右边)到浏览窗口左边(右边)的像素值
yPx:110/任意数字 垂直方向上Logo顶边(底边)到浏览窗口顶边(底边)的像素值
operaShow:true/false 因为Opera目前不支持as和js通信,可以Opera下对联无法关闭,可以通过false来设置Opera下对联不显示
*/
var nadCouplet = function(url,id,options){
if(window.screen.width<1024){return;}
if(nadIsLtIE5_5()){return;}
if(!url){return;}else{this.url = url;}
if(!id){return;}else{this.id = id;}
this.options = {
width: 110,
height: 260,
x: 'left',
xPx: 0,
yPx: 110,
operaShow: true
}
Object.nadExtend(this.options,options||{});
if(!this.options.operaShow && nadIsOpera){return;}
this.create();
}
nadCouplet.prototype={
create:function(){
var wrap = document.createElement('span');
var _opt = this.options;
var _x = _opt.x;
var _id = this.id
var id = _id + _x;
if(_x=='left'){_id += 'right';}
else{_id += 'left';}
wrap.style.position = 'absolute';
wrap.innerHTML = nadCreateSwfHtml(this.url,id,{
width : _opt.width,
height : _opt.height,
quality : 'high',
wmode : 'window'
});
wrap.style[_opt.x] = _opt.xPx + 'px';
wrap.style.top = _opt.yPx + 'px';
document.getElementById("ssid1").appendChild(wrap);
this.ad = wrap;
this.initScrollTop = 0;
var _fscHtml ='';
_fscHtml += '<script type="text/javascript">';
_fscHtml += 'function '+ id +'_DoFSCommand(command,args){'
_fscHtml += 'if (command == "quit"){'
_fscHtml += 'document.getElementById("'+ id +'").parentNode.style.visibility = "hidden";';
_fscHtml += 'if(document.getElementById("'+ _id +'")){document.getElementById("'+ _id +'").parentNode.style.visibility = "hidden";}';
_fscHtml += '}}';
_fscHtml += '<\/script>';
if(nadIsIE){
_fscHtml += '<script type="text/javascript" for="'+ id +'" event="FSCommand(command,args)">';
_fscHtml += id + '_DoFSCommand(command,args)';
_fscHtml += '<\/script>';
}
document.write(_fscHtml);
}
}
/*==common function==*/
var nadUserAgent = navigator.userAgent;
var nadIsOpera = nadUserAgent.indexOf('Opera')>-1
var nadIsIE = nadUserAgent.indexOf('MSIE')>-1 && !nadIsOpera;
var nadIsLtIE5_5 = function(){
if(nadIsIE){
var reIE = new RegExp('MSIE (\\d+\\.\\d+);');
reIE.test(nadUserAgent);
var IeVersion = parseFloat(RegExp["$1"]);
return IeVersion <5.5;
}
}
Object.nadExtend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var nadCreateSwfHtml = function(url,id,options){
var swfHtml='';
if(!url){return;}
_opt = options;
if(nadIsIE){
swfHtml += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ _opt.width +'" height="'+ _opt.height +'" id="'+ id +'">';
swfHtml += '<param name="movie" value="'+ url +'" />';
swfHtml += '<param name="allowScriptAccess" value="always" />';
swfHtml += '<param name="quality" value="'+ _opt.quality +'" />';
swfHtml += '<param name="wmode" value="opaque" />';
swfHtml += '</object>';
}
else{
swfHtml += '<embed src="'+ url +'" quality="'+ _opt.quality +'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ _opt.width +'" height="'+ _opt.height +'" wmode="opaque" id="'+ id +'" name="'+ id +'" swliveconnect="true"></embed>'
}
return swfHtml;
}
/*==common function==*/
将上面的代码保存为*.js 或者从下面下载也可以。
在网页中插入如下代码即可。
<div id="id标记"></div>
<script type="text/javascript" src="*.js"></script>
<script type="text/javascript">
new nadCouplet(
' flash 地址1 ',
'nad4207Home');
new nadCouplet(
' flash 地址2 ' ,
'nad4207Home',
{x:'right'});
</script>
<script type="text/javascript" src="*.js"></script>
<script type="text/javascript">
new nadCouplet(
' flash 地址1 ',
'nad4207Home');
new nadCouplet(
' flash 地址2 ' ,
'nad4207Home',
{x:'right'});
</script>
地址可为相对路径也可以为决定路径
点击下载此文件
[本日志由 田草 于 2008-05-12 10:03 PM 编辑]
|
田草 于 2008-07-17 11:48 AM 发表评论:
<SCRIPT type=text/javascript>
var tips1;var tips2; var zh_theTop = 180/*这是默认高度*/; var old = zh_theTop;
function initFloatTips() {
tips1 = document.getElementById('adleft');
tips2 = document.getElementById('adright');
moveTips();
};
var zh_pos;
function moveTips() {
var tt=50;
if (window.innerHeight) {
zh_pos = window.pageYOffset
}
else if (document.documentElement && document.documentElement.scrollTop) {
zh_pos = document.documentElement.scrollTop
}
else if (document.body) {
zh_pos = document.body.scrollTop;
}
zh_pos=zh_pos-tips1.offsetTop+zh_theTop;
zh_pos=tips1.offsetTop+zh_pos/5;
if (zh_pos < zh_theTop) zh_pos = zh_theTop;
if (zh_pos != old) {
tips1.style.top = zh_pos+"px";
tips2.style.top = zh_pos+"px";
tt=10;
}
old = zh_pos;
setTimeout(moveTips,tt);
}
initFloatTips() ;
</SCRIPT>
<DIV id=adleft style="RIGHT: 2px; LINE-HEIGHT: 150%; POSITION: absolute; TOP: 150px; left: 910px; float:right">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD vAlign=top height=108>
<TABLE cellSpacing=0 cellPadding=0 width=93 border=0>
<TBODY>
<TR>
<TD width=107><EMBED src='EccoolAda.swf' wmode='transparent' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=EccoolAd></EMBED></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<DIV id=adright style="LEFT: 1px; LINE-HEIGHT: 150%; POSITION: absolute; TOP: 150px">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD vAlign=top height=108>
<TABLE cellSpacing=0 cellPadding=0 width=97 border=0>
<TBODY>
<TR>
<TD colSpan=6 height=93><EMBED src='EccoolAdb.swf' wmode='transparent' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=EccoolAd></EMBED></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
var tips1;var tips2; var zh_theTop = 180/*这是默认高度*/; var old = zh_theTop;
function initFloatTips() {
tips1 = document.getElementById('adleft');
tips2 = document.getElementById('adright');
moveTips();
};
var zh_pos;
function moveTips() {
var tt=50;
if (window.innerHeight) {
zh_pos = window.pageYOffset
}
else if (document.documentElement && document.documentElement.scrollTop) {
zh_pos = document.documentElement.scrollTop
}
else if (document.body) {
zh_pos = document.body.scrollTop;
}
zh_pos=zh_pos-tips1.offsetTop+zh_theTop;
zh_pos=tips1.offsetTop+zh_pos/5;
if (zh_pos < zh_theTop) zh_pos = zh_theTop;
if (zh_pos != old) {
tips1.style.top = zh_pos+"px";
tips2.style.top = zh_pos+"px";
tt=10;
}
old = zh_pos;
setTimeout(moveTips,tt);
}
initFloatTips() ;
</SCRIPT>
<DIV id=adleft style="RIGHT: 2px; LINE-HEIGHT: 150%; POSITION: absolute; TOP: 150px; left: 910px; float:right">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD vAlign=top height=108>
<TABLE cellSpacing=0 cellPadding=0 width=93 border=0>
<TBODY>
<TR>
<TD width=107><EMBED src='EccoolAda.swf' wmode='transparent' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=EccoolAd></EMBED></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<DIV id=adright style="LEFT: 1px; LINE-HEIGHT: 150%; POSITION: absolute; TOP: 150px">
<TABLE cellSpacing=0 cellPadding=0 width=100 border=0>
<TBODY>
<TR>
<TD vAlign=top height=108>
<TABLE cellSpacing=0 cellPadding=0 width=97 border=0>
<TBODY>
<TR>
<TD colSpan=6 height=93><EMBED src='EccoolAdb.swf' wmode='transparent' quality=high WIDTH=100 HEIGHT=300 TYPE='application/x-shockwave-flash' id=EccoolAd></EMBED></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</DIV>
发表评论 - 不要忘了输入验证码哦! |