| Page Item | Value |
| Title | A JavaScript Banner Ad Rotator Script |
| Description | JavaScript banner ad rotator script |
| Keywords | javascript, banner, free script, advert, rotator, ad |
| Robots Meta Tag | |
| Page Content | HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | TOOLS | GALLERY | CONTACT Search: Go DEVELOPER TOOLS ASP Doc Tool ASP.NET Doc Tool SQL Doc Tool Index Server Companion The Website Utility TECHNICAL ARTICLES ASP ASP.NET JavaScript Transact SQL PHOTO GALLERIES Canon EOS 300D Samples Red Arrows 2004 Living Coasts Web Page Backgrounds More Galleries... NEW STUFF SQL Color Coder Canon EOS 300D Samples The Website Utility Search Engine Optimisation Build an ASP Search Engine My Tropical Fishtank Savings Other New Stuff... POPULAR STUFF Regular Expressions ASP Documentation Tool Index Server ASP JavaScript Ad Rotator LINKS Business Website ASPAlliance Articles
Home Articles A JavaScript Banner Ad Rotator Script This script was written to address some of the shortcomings of some other methods for creating rotating banner advertisements Banner Ads , namely: The Banner Ad Manager that comes with Microsoft FrontPage uses Java to create a banner that changes on the page. This has the problem that it takes a few seconds for the Java Applet to load, and each image in the sequence cannot point to a different URL. The Ad Rotator Active Server Component of Microsoft's Internet Information Server can insert a random image on a page, with each image pointing to an appropriate URL. But each Ad can only display a single image each time the page is loaded. The script described here addresses both problems. It displays a different image after a specific amount of time, and clicking on each of the images in the sequence will take you to a different URL. An example banner can be viewed below: Adding the script to a page There are several requirements for this script: You need several, identically sized images. The images can be in any format supported by browsers (i.e. GIF, PNG or JPEG). The example described in this article uses four different images, each of which is 468 pixels wide and 60 pixels high. You need to add some extra code to your HTML document. For the script to work there must be an initial image on the web page. In this case the image has a filename of bb-amazon-ad1.gif. This image will also be visible when the page is viewed in browsers that do not support the script. After loading the image, its width and height should be specified, and it should also be given the name attribute of bannerad . The image should be hyperlinked so that the ChangePage JavaScript function is executed when the image is clicked on. Example code for including the initial image is shown below: a href= javascript:ChangePage() img src= images/AmazonAd1_anim.gif alt= Banner Advertisement border= 0 hspace= 0 name= bannerad WIDTH= 466 HEIGHT= 58 /a You also need to modify the BODY HTML tag of the page so that when the page is loaded, it executes the InitialiseBannerAdRotator function. Do this by adding the onload tag, as shown below: body onload= InitialiseBannerAdRotator() Finally, you need to add the following script to the page (within the HEAD part of the page is the ideal location): script language= javascript !-- A link at the bottom of this article will allow you to download a ZIP file containing the script and example images. Script ParametersThe script has a number of parameters in the section headed User defined variables , which you will need to change in order to customise the script. The parameters are described below: ImageFolder - the name of the folder containing the images. Leave as if the images are in the same folder as the document containing the banner ad rotator JavaScript. ImageFileNames - this should be a list of images to use with the script. ImageURLs - this should be a list of URLs to associate with the list of images. Needless to say, the number of items in this list should be the same as the number of images. DefaultURL - the default URL the banner ad rotator should link to. This hyperlink is the one browsers are redirected to if the banner ad image is clicked on with a browser that is not fully supported by the script. DisplayInterval - the time interval (in seconds) before the next image is displayed. TargetFrame - the name of the frame in which to open the URL in. Leave as if the banner ad should open the URL in the same frame as the page containing the script. How the Script WorksWhen the web page is first loaded into the web browser, it runs the function InitialiseBannerAdRotator. The first part of this function determines the name and version of the browser the script is being run on, setting the variable IsValidBrowser to true if the browser is supported by the script. Browsers supported by the script are Netscape versions of 3 and above, and Microsoft Internet Explorer 4 and above. The InitialiseBannerAdRotator function then sets a timer called TimerObject for the time interval specified in the user defined variables. When this timer reaches zero, it then runs the ChangeImage function (the use of which is described further on). The function also assigns zero to the BannerAdCode variable. This variable is used to cycle through the different images to be shown. Finally, the function pre-loads the images required by the script. The second function in the script is called ChangeImage. This function increases the value of the BannerAdCode variable, ensuring that if it is too large for the number of different images, it is reset to zero. After changing the BannerAdCode variable, the function changes the image source ( src ) of the image that has the name of bannerad to point to the next image in the sequence. This is the part of the script which actually changes the image on the page. The final function in the script is called ChangePage, and is called when the Banner Ad is clicked on. This function reads the value of BannerAdCode, then sets the document (or frame) location to the new location. location is a built-in feature of JavaScript that allows you to specify the URL of the page loaded in the web browser. Note that if the banner is being viewed in a browser not supported by the script, it will set the page location to that specified in the DefaultURL variable. LimitationsThere can only be one instance of a banner ad per page on your site, although with a few modifications the script could support several banners per page. Don't forget that adding too much advertising to your site will distract users, so use sparingly. The script currently cycles through a series of images, but it would not be too difficult to modify it to show the images in a random order. The script doesn't open links in a new browser window. If you want the commercial version of the script that does, then you can purchase the full version for just $3 . If you purchase any of my other software products ( ASP Documentation Tool , ASP.NET Documentation Tool , Index Server Companion ) then let me know and I'll send you the script for free! DownloadsIf you would like the Banner Ad Rotator script together with some sample images, then click on the link below: Banner Ad Rotator sample files (37.9 Kb ZIP file). Further ReadingWant to help your website vistors find stuff? Then put a JavaScript Search Engine on your website! Enhance your knowledge of JavaScript with the following: JavaScript bible . Javascript : The Definitive Guide . Javascript Pocket Reference . Alternatives to using this Banner Ad script: A Java version of the Banner Ad Rotator. Using the Ad Rotator . Site MapAll content is © 1995 - 2006 Brett Burridge |
| Image Alt Tags | Brettb.Com Microsoft Certified Professional Banner Advertisement |
| Internal Links | http://www.brettb.com/Default.asp (3 links in this page) [ Robot View of this URL ] http://www.brettb.com/ASPDocumentationTool.asp (2 links in this page) [ Robot View of this URL ] http://www.brettb.com/technicalwriting.asp (2 links in this page) [ Robot View of this URL ] http://www.brettb.com/DeveloperTools.asp (2 links in this page) [ Robot View of this URL ] http://www.brettb.com/TheWebsiteUtility.asp (2 links in this page) [ Robot View of this URL ] http://www.brettb.com/SearchingIndexServerWithASP.asp [ Robot View of this URL ] http://www.brettb.com/JavaScriptArticles.asp [ Robot View of this URL ] http://www.brettb.com/Website_Search_Engine_Optimisation.asp [ Robot View of this URL ] http://www.brettb.com/SearchResults.asp [ Robot View of this URL ] http://www.brettb.com/js_banner_ad_rotator.asp [ Robot View of this URL ] http://www.brettb.com/web.asp [ Robot View of this URL ] http://www.brettb.com/CanonEOS300D_Gallery1.asp [ Robot View of this URL ] http://www.brettb.com/BuildingAnASPSearchEngine.asp [ Robot View of this URL ] http://www.brettb.com/backgrounds.asp [ Robot View of this URL ] http://www.brettb.com/VBScriptRegularExpressions.asp [ Robot View of this URL ] http://www.brettb.com/JavaBannerAdRotator.asp [ Robot View of this URL ] http://www.brettb.com/toc.asp [ Robot View of this URL ] http://www.brettb.com/ASP.NETArticles.asp [ Robot View of this URL ] http://www.brettb.com/Investments_ISAs.asp [ Robot View of this URL ] http://www.brettb.com/TransactSQLColorCoder.asp [ Robot View of this URL ] http://www.brettb.com/MyTropicalFishtank.asp [ Robot View of this URL ] http://www.brettb.com/CanonEOS300D_Gallery3.asp [ Robot View of this URL ] http://www.brettb.com/ASPWatchArticles.asp [ Robot View of this URL ] http://www.brettb.com/Red_Arrows_2004.asp [ Robot View of this URL ] http://www.brettb.com/Living_Coasts_Photos.asp [ Robot View of this URL ] http://www.brettb.com/SQL_Help.asp [ Robot View of this URL ] http://www.brettb.com/contact.asp [ Robot View of this URL ] http://www.brettb.com/Biotechnology.asp [ Robot View of this URL ] http://www.brettb.com/Gallery.asp [ Robot View of this URL ] http://www.brettb.com/ASPNetDocumentationTool.asp [ Robot View of this URL ] http://www.brettb.com/gallery.asp [ Robot View of this URL ] http://www.brettb.com/what's_new.asp [ Robot View of this URL ] http://www.brettb.com/IndexServerCompanion.asp [ Robot View of this URL ] http://www.brettb.com/redirector.asp [ Robot View of this URL ] |
Report generated by The Website Utility 2.8