ASP.NET
  Home arrow ASP.NET arrow Page 2 - Programming an In-Text Advertising System ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Programming an In-Text Advertising System under ASP.NET 3.5
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2009-01-21

    Table of Contents:
  • Programming an In-Text Advertising System under ASP.NET 3.5
  • The JavaScript files
  • The Server-side Programming
  • The Three Generic Handlers Related Programming

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programming an In-Text Advertising System under ASP.NET 3.5 - The JavaScript files


    (Page 2 of 4 )

    There are mainly three script files defined in this system, i.e. xmlhttp.js, ad.js and getAd.js. First, the xmlhttp.js file encapsulates the Ajax core (i.e. XMLHTTP) related calling code. Here, we are not going to delve into it because most developers are familiar with the basic Ajax-related concepts. You can refer to the source code to find out the details.


    The second script file, ad.js, is really the core script. It takes the responsibility of rendering the in-text ad contents. The third script file, getAd.js, encapsulates the ad placing related code, which, in fact, further invokes several other files.


    Now, let’s first look more closely at file getAd.js:

    document.write('<script type="text/javascript" src="js/xmlhttp.js"></script>');

    document.write('<script type="text/javascript" src="adArray.ashx"></script>');

    document.write('<script type="text/javascript" src="js/ad.js"></script>');

    Wherein, the adArray.ashx file is responsible for generating the ad keyword array dynamically, whose detailed implementation will be discussed later. The ad.js file, however, takes charge of generating the concrete ad code. To more clearly comprehend this file, Figure 2 shows the invoking relationships between the several functions inside of it.


    Figure 2—the invoking relationships between the several functions inside the ad.js file

    Now, let’s delve into the implementation of the matchAds function. First of all, we should create an HTML <div/> element that represents the ad window to show and specify the related attributes and styles as follows:

    function matchAds(e)

    {

    var AdShowBox=document.createElement("div");

    AdShowBox.id="AdShowBox";

    AdShowBox.setAttribute("id","AdShowBox");

    AdShowBox.setAttribute("name","aspx1");

    AdShowBox.style.width=AdBoxWidth;

    AdShowBox.style.height=AdBoxHeight;

    AdShowBox.style.position="absolute";

    AdShowBox.innerHTML="<div id="AdShowBoxBar" name="aspx1"><div id="AdShowBoxBartitle" name="aspx1"></div><div id="AdShowBoxBarClose" name="aspx1"><img name="aspx1" src="img/close.jpg" width="14" height="14" border="0" onclick="hiddenAdShowBox()" /></div></div><div id="AdShowBoxContent" name="aspx1"></a></div>";

    ……

    Please pay special attention to the complex contents of the innerHTML element of the AdShowBox element above.


    Next, as you will imagine, we should attach the above newly-created <div/> element to the HTML document:

    document.body.appendChild(AdShowBox);

    Next, we obtain the specified matching area, which is the only argument passed to the matchAds(); function: 

    var obj=$(e);

    if(!obj) obj = document.body.childNodes[0];

    if(obj.innerHTML=="")obj = document.body.childNodes[1];

    Next, continue to work with the matched element, to get its attribute innerHTML and iterate through it to find out all the keywords and replace them with the ad styled hyperlinks:

    var tmp=obj.innerHTML;

    for(var i=0;i<Ads.length;i++)

    {

    Adzz=eval("/"+Ads[i]+"/g");

    tmp=tmp.replace(Adzz,"<a oncontextmenu="return false;" onmousemove="moveAdBox(event);" onmouseover="showAdsearch('"+Ads[i]+"',event);" style="color:Red" name="aspx1" target="_blank">"+Ads[i]+"</a>");

    }

    obj.innerHTML=tmp;//substitute

    }

    As you’ve seen, inside the matchAds function, the other functions (in Figure 2 above) are invoked, where the showAdsearch function undertakes the task of obtaining the ad contents related to some specified keyword, the moveAdBox function is responsible for moving the ad window, and the hiddenAdShowBox function can hide the ad window when needed. For brevity, we omit their code listings here.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek