导航

一些关于广告管理系统的代码收集

Posted on 2006-03-28 21:55  兰宝石.NET  阅读(671)  评论(1编辑  收藏  举报

一、对联广告
<script language="JavaScript">

function top(url){
 iframetop.location.href = url;
 }

</script>
 <script language="JavaScript">
<!--
if(parseInt(navigator.appVersion.charAt(0))<4){
location.href="/web3/main.jsp"
}

brOK=navigator.javaEnabled()?true:false
ns4=(document.layers)?true:false
ie4=(document.all)?true:false

if(ns4){
document.write('<layer id="mvt" width=40 height=60;"><iframe height=128 width=128 frame=0 frameborder=0 marginheight="0" marginwidth="0" scrolling="no" src="/web3/flowtop.jsp"></iframe><\/layer>');

}
else{
document.write('<div id="mvt" style="position:absolute; width:40; height:60;"><iframe height=128 width=128  frame=0 frameborder=0 marginheight="0" marginwidth="0" scrolling="no" src="/web3/flowtop.jsp"></iframe><\/div>');
}


var vmin=2;
var vmax=5;
var vr=2;
var timer1;
function Chip(chipname,width,height)
{this.named=chipname;
 this.vx=vmin+vmax*Math.random();
 this.vy=vmin+vmax*Math.random();
 this.w2=width;
 this.h2=height;
 this.xx=0;
 this.yy=0;
 this.timer1=null;
}

function movechip(chipname)
{
 if(brOK)
{eval("chip="+chipname);
if(ns4)
{pageX=window.pageXOffset;
pageW=window.innerWidth;
pageY=window.pageYOffset;
pageH=window.innerHeight;
}
else
{pageX=window.document.body.scrollLeft;
pageW=window.document.body.offsetWidth-8;
pageY=window.document.body.scrollTop;
pageH=window.document.body.offsetHeight;
}

chip.xx=chip.xx+chip.vx;
chip.yy=chip.yy+chip.vy;

chip.vx+=vr*(Math.random()-0.5);
chip.vy+=vr*(Math.random()-0.5);
if(chip.vx>(vmax+vmin))chip.vx=(vmax+vmin)*2-chip.vx;
if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
if(chip.vy>(vmax+vmin))chip.vy=(vmax+vmin)*2-chip.vy;
if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;


if(chip.xx<=pageX)
{chip.xx=pageX;
chip.vx=vmin+vmax*Math.random();
}
if(chip.xx>=pageX+pageW-chip.w)
{chip.xx=pageX+pageW-chip.w;
chip.vx=-vmin-vmax*Math.random();
}
if(chip.yy<=pageY)
{chip.yy=pageY;
chip.vy=vmin+vmax*Math.random();
}
if(chip.yy>=pageY+pageH-chip.h)
{chip.yy=pageY+pageH-chip.h;
chip.vy=-vmin-vmax*Math.random();
}

if(ns4){
eval('document.'+chip.named+'.top ='+chip.yy);
eval('document.'+chip.named+'.left='+chip.xx);
}
else{
eval('document.all.'+chip.named+'.style.pixelLeft='+chip.xx);
eval('document.all.'+chip.named+'.style.pixelTop ='+chip.yy);
}
chip.timer1=setTimeout("movechip('"+chip.named+"')",100);
}
}

function stopme(chipname)
{if(brOK)
{//alert(chipname)
eval("chip="+chipname);
if(chip.timer1!=null)
{clearTimeout(chip.timer1)}
}
}

var mvt;
function mvt()
{
mvt=new Chip("mvt",80,80);
if(brOK){
movechip("mvt");
}
}

window.onload=mvt

//-->
</script>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>::欢迎使用广东移动彩铃业务::</title>
<link href="/css/web/style.css" rel="stylesheet" type="text/css">
</head>

二、关于AdRotator的使用
在 Web 窗体页上显示公布标志。
<asp:AdRotator
     id="Value"
     AdvertisementFile="AdvertisementFile"
     KeyWordFilter="KeyWord"
     Target="Target"
     OnAdCreated="OnAdCreatedMethod"
     runat="server"/>
公布文件格式
AdRotator 控件使用单独的 XML 公布文件存储公布信息,如要显示的图像的位置以及要链接到的页的 URL。AdRotator 控件的 AdvertisementFile 属性指定该文件的路径。
创建公布文件时,开始和结束 <Advertisements> 标记分别标记该文件的开头和结尾。开始和结束 <Ad> 标记划定每个公布的界线。所有公布都嵌套在开始和结束 <Advertisements> 标记之间。如果该文件包含多个 <Advertisements> 标记,则 AdRotator 控件只分析该文件中的第一组 <Advertisements> 标记。所有其他 <Advertisements> 标记都将被忽略。
每个公布的数据元素都嵌套在开始和结束 <Ad> 标记之间。尽管某些数据元素是预定义的(如 ImageUrl 和 NavigateUrl),但仍可以在 <Ad> 标记之间放置自定义元素。AdRotator 控件在分析该文件时将读取这些元素。然后将该信息传递给 AdProperties 词典属性中的 AdCreated 事件。
下表列出为 XML 公布文件预定义的数据元素。
元素说明
<ImageUrl>图像文件的绝对或相对 URL(可选)。
<NavigateUrl>当用户单击公布时要链接到的页的 URL(可选)。
注意   如果未设置此元素,则 HRef 属性不会呈现在定位点标记上。
<AlternateText>当由 ImageUrl 属性指定的图像不可用时替换该图像的文本显示(可选)。
在某些浏览器中,该文本也显示为公布的 ToolTip。
<Keyword>可用作筛选依据的公布类别(如“computers”)(可选)。
<Impressions>指示公布在轮换安排中相对于文件中其他公布的重要性的数字(可选)。
数字越大,显示该公布的频率越高。XML 文件中所有 Impressions 值的总和不能超过 2,047,999,999。如果超过该值,则 AdRotator 将引发运行时异常。

以下内容显示 XML 公布文件的格式。
<Advertisements>
   <Ad>
      <ImageUrl>
         URL of image to display for Advertisement #1
      </ImageUrl>
      <NavigateUrl>
         URL of page to link to for Advertisement #1
      </NavigateUrl>
      <AlternateText>
         Text to show as a ToolTip for Advertisement #1
      </AlternateText>
      <Keyword>
         Keyword used to filter for Advertisement #1
      </Keyword>
      <Impressions>
         Relative importance of Advertisement #1
      </Impressions>
      <CustomInformation>
         Custom Data about Advertisement #1
      </CustomInformation>
   </Ad>
</Advertisements>
备注
AdRotator 控件在 Web 窗体页上显示公布标志。它显示由定位点控件内的 ImageUrl 元素指定的图像。在运行时,AdRotator 控件使用 <asp:HyperLink> 和 <asp:Image> 控件在 Web 窗体页上呈现该控件。浏览器将源图像的大小调整为 AdRotator 控件的尺寸,而无论其实际大小如何。
如果设置了 AdvertisementFile 属性,则根据 Impressions 属性的值从文件中选择一个公布。然后设置事件参数并引发 AdCreated 事件。如果未设置 AdvertisementFile 属性,则引发 AdCreated 事件时事件参数为空。事件参数用于呈现 AdRotator 控件,以便您可以修改从公布文件传递给该事件的值,或用您自己生成的值来设置这些值。通常情况下,使用从数据库中检索到的值来填充事件参数。
创建公布文件时,请考虑以下几点:
公布文件中的 XML 必须格式正确。
AdRotator 控件只分析文件中的第一个 <Advertisements> 元素。该文件中的所有其他 <Advertisements> 元素均被忽略。
可以向公布的 XML 说明中添加自定义元素。这些值被传递给 AdProperties 词典属性中的 AdCreated 事件。
可使用 AdCreated 事件直接在代码中选择公布或修改从公布文件中选定的公布的呈现方式。如果设置了公布文件,则在调用该事件时,AdCreated 事件的参数将已经设置为选定的公布。无论是否已经设置这些值,都可以修改 ImageUrl、NavigateUrl 和 AlternateText 属性中的值以修改 AdRotator 控件的呈现方式。添加到公布的 XML 说明中的自定义元素可用于 AdCreatedEventArgs.AdProperties 词典属性。
有关 AdRotator 控件的属性和事件的详细信息,请参见 AdRotator 类文档。
示例
以下示例说明如何在 .aspx 文件中声明 AdRotator 控件。
<html>
 
   <head>
   </head>
 
<body>
   <form runat="server">
 
      <h3>AdRotator Example</h3>
 
      <asp:AdRotator id="AdRotator1"
           Target="_self"
           AdvertisementFile="Ads.xml"
           runat="server"/>
 
   </form>
</body>
 
</html>
以下示例说明如何为 AdCreated 事件创建事件处理程序来以编程方式重写 NavigateUrl 属性的值。
[Visual Basic]
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">
  
      Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs)

         e.NavigateUrl = "http://www.microsoft.com/china"  
      
      End Sub     

   </script>
 
</head>
 
<body>
 
   <form runat="server">
 
      <h3>AdRotator Example</h3>
 
      <asp:AdRotator id="AdRotator1" runat="server"
           AdvertisementFile = "Ads.xml"
           Target="_newwwindow"
           OnAdCreated="AdCreated_Event"/>
 
   </form>
 
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">
  
      void AdCreated_Event(Object sender, AdCreatedEventArgs e)
      {

         e.NavigateUrl = "http://www.microsoft.com/china";  
      
      }     

   </script>
 
</head>
 
<body>
 
   <form runat="server">
 
      <h3>AdRotator Example</h3>
 
      <asp:AdRotator id="AdRotator1" runat="server"
           AdvertisementFile = "Ads.xml"
           Target="_newwwindow"
           OnAdCreated="AdCreated_Event"/>
 
   </form>
 
</body>
</html>
以下示例说明如何格式化 XML 公布文件。
<Advertisements>
 
   <Ad>
      <ImageUrl>image1.jpg</ImageUrl>
      <NavigateUrl>http://www.microsoft.com/china</NavigateUrl>
      <AlternateText>Microsoft Main Site</AlternateText>
      <Impressions>80</Impressions>
      <Keyword>Topic1</Keyword>
      <Caption>This is the caption for Ad#1</Caption>
   </Ad>
 
   <Ad>
      <ImageUrl>image2.jpg</ImageUrl>
      <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>
      <AlternateText>Wing Tip Toys</AlternateText>
      <Impressions>80</Impressions>
      <Keyword>Topic2</Keyword>
      <Caption>This is the caption for Ad#2</Caption>
   </Ad>
 
</Advertisements>

三、关于浮动广告

a.htm、a.asp、a.aspx文件的源代码如下:
========================================
<html>
<head>

</head>
<body>
<script src="Css/S.JS"></script>

</body>
</html>
========================================

S.JS文件的源代码如下(网上共用的)

var delta=0.5;
 var collection;
 var closeB=false;
 function floaters() {
 this.items = [];
 this.addItem = function(id,x,y,content)
   {
   document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
  
   var newItem  = {};
   newItem.object  = document.getElementById(id);
   newItem.x  = x;
   newItem.y  = y;

   this.items[this.items.length] = newItem;
   }
 this.play = function()
   {
   collection  = this.items
   setInterval('play()',1);
   }
 }
 function play()
 {
  if(screen.width<=800 || closeB)
  {
  for(var i=0;i<collection.length;i++)
  {
   collection[i].object.style.display = 'none';
  }
  return;
  }
  for(var i=0;i<collection.length;i++)
  {
  var followObj = collection[i].object;
  var followObj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
  var followObj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);

  if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
   var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
   dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
   followObj.style.left=followObj.offsetLeft+dx;
   }

  if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
   var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
   dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
   followObj.style.top=followObj.offsetTop+dy;
   }
  followObj.style.display = '';
  }
 }
 function closeBanner()
 {
  closeB=true;
  return;
 }

 var theFloaters = new floaters();
 //
 theFloaters.addItem('followDiv1','document.body.clientWidth-125',30,'<img src="image/denglong.jpg">');
 theFloaters.addItem('followDiv2',2,6,'<br/><img src="image/denglong.jpg">');
 theFloaters.play();



<div id="_im" style="VISIBILITY: visible; POSITION: absolute;" onmouseover="clearTimeout(timerid1)" onmouseout="timerid1 = setTimeout('animate()', 30);"><a href="http://dotnet.aspx.cc/Images/logoSite.gif" target=blank )"><img src="http://dotnet.aspx.cc/Images/logoSite.gif"  border="0"></a></div>
<!-- 此行为注释:可以全部删除。以下不要动,如果修改图片或者链接,只需要修改上面的HTML部分即可 -->
<script language="javascript">
<!-- 脚本开始
var divWidth = 220
var divHeight = 60
var isNS = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
var _all = '';
var _style = '';
var wwidth, wheight;
var ydir = '++';
var xdir = '++';
var timerid1, timerid2, timerid3;
var x = 1;
var y = 300;
var x1, y1;
if(!isNS) {
_all='all.';
_style='.style';
}

function getwindowsize() {
clearTimeout(timerid1);
clearTimeout(timerid2);
clearTimeout(timerid3);
if (isNS) {
wwidth = window.innerWidth - divWidth;
wheight = window.innerHeight - divHeight;
} else {
wwidth = document.body.clientWidth - divWidth;
wheight = document.body.clientHeight - divHeight;
}
timerid3 = setTimeout('randomdir()', 20000);
animate();
}

function randomdir() {
if (Math.floor(Math.random()*2)) {
(Math.floor(Math.random()*2)) ? xdir='--': xdir='++';
} else {
(Math.floor(Math.random()*2)) ? ydir='--': ydir='++';
}
timerid2 = setTimeout('randomdir()', 20000);
}

function animate() {
eval('x'+xdir);
eval('y'+ydir);
if (isNS) {
pic1.moveTo((x+pageXOffset),(y+pageYOffset))
} else {
pic1.pixelLeft = x+document.body.scrollLeft;
pic1.pixelTop = y+document.body.scrollTop;
}
if (isNS) {
if (pic1.top <= 5+pageYOffset) ydir = '++';
if (pic1.top >= wheight+pageYOffset) ydir = '--';
if (pic1.left >= wwidth+pageXOffset) xdir = '--';
if (pic1.left <= 5+pageXOffset) xdir = '++';
} else {
if (pic1.pixelTop <= 5+document.body.scrollTop) ydir = '++';
if (pic1.pixelTop >= wheight+document.body.scrollTop) ydir = '--';
if (pic1.pixelLeft >= wwidth+document.body.scrollLeft) xdir = '--';
if (pic1.pixelLeft <= 5+document.body.scrollLeft) xdir = '++';
}
timerid1 = setTimeout('animate()', 30);
}
var pic1=eval('document.'+_all+'_im'+_style);
window.onload=getwindowsize
window.onresize=getwindowsize
window.onerror = function(){return false}
//  脚本结束 -->
</script>

给浮动广告上加一个“关闭”按钮
<div id="_im" style="VISIBILITY: visible; POSITION: absolute;" onmouseover="clearTimeout(timerid1)" onmouseout="timerid1 = setTimeout('animate()', 30);"><a href="http://dotnet.aspx.cc/Images/logoSite.gif" target=blank )"><img src="http://dotnet.aspx.cc/Images/logoSite.gif"  border="0"></a> <a href="" onclick="clearTimeout(timerid1);clearTimeout(timerid2);clearTimeout(timerid3);_im.parentNode.removeChild(_im);return false">关闭</a></div>