Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

Macromedia Fireworks Image Map Tutorial

A JavaScript Picture Gallery

Speeding up image rollovers

Fading Images in and out

Controlling Images #2

Controlling Images

Image Maps

Toolbar Images

Random Banner Adverts

Highlighting Images (#2)

The Book of the Day Script

You are here: irt.org | Articles | JavaScript | Image | The Book of the Day Script [ previous next ]

Published on: Sunday 20th June 1999 By: Ben Allen

Introduction

Do you have an affiliate program for your website? Would you like to improve revenue by cycling which book is displayed depending on the day? The script below does just that, for the Amazon.co.uk affiliate program, although it can be used for the Amazon.com program with a few simple alterations.

Warning - This code will only work in Version 4 browsers!

Working Example

Once finished, the code will look like this, with the book changing each day, on a repeating cycle:

Book of the Day


The JavaScript Source Code

The code for this can be seen below:

<script language="JavaScript1.2"><!--
/************************************
 Book of the day script      
 Written by Ben Allen 1999  
 http://javascript.connect-2.co.uk 
************************************/

mybooks = 4;
today = new Date();
number = today.getDate();
number %= mybooks;
affid = 'dynamicit';
number++;

switch(number) {
// Book Details Start
    case 0:
        refno='0201696487';
        bname='JavaScript For The World Wide Web';
        break;
    case 1:
        refno='0764530224';
        bname='JavaScript Bible';
        break;
    case 2:
        refno='0764502239';
        bname='JavaScript For Dummies';
        break;
    case 3:
        refno='0471181455';
        bname='JavaScript Cookbook';
        break;
// Book Details End
}

document.write('<a href="http://www.amazon.co.uk/exec/obidos/ASIN/' + refno + '/' + affid + '" target="_top" onMouseOver="self.status=\'Click here to buy from Amazon.co.uk\';" onMouseOut="self.status=\'Done\';">");
document.write('<img src="book' + (number) + '.gif" alt="' + bname + ' - Click here to buy from Amazon.co.uk" width="110"><p>');
document.write('<font face="Arial" size="1" color="#80c0ff">' + bname + '</font><br>');
document.write('</a>');
//--></script>

Adapting the script for your site

If you wish to use this script for an Amazon.com referral program, change the line:

document.write('<a href="http://www.amazon.co.uk/exec/obidos/ASIN/" + refno + ...

to:

document.write('<A HREF="http://www.amazon.com/exec/obidos/ASIN/" + refno + ...

And change the message in the next line from " - Click here to buy from Amazon.co.uk" to whatever you want to appear.

Change the line affid = 'dynamicit', replacing dynamicit with your associate ID. If you fail to do this, people buying books will earn money for me, and not you! (Not that I mind).

Now comes the difficult bit - adding the books you wish to sell. First, save all the images of the books you wish to sell in the same directory as the HTML page. Save them as .gif files named from book1.gif up the the number of books you wish to sell, e.g. if you wished to sell 5 different books, you would save them as book1.gif, book2.gif, book3.gif, book4.gif, and book5.gif.

Now you need to enter the book details. These are entered between the tags:

// Book Details Start

// Book Details End

In our example above, I am selling four books, entitled JavaScript for the World Wide Web, JavaScript Bible, JavaScript for Dummies, and JavaScript Cookbook. These are entered as follows:

For book number 1, entitled "JavaScript for Dummies", saved as book1.gif

    case 1:
        refno='0764502239';
        bname='JavaScript for Dummies';
        break;

In this case, the number in the line refno='0764502239'; refers to the book reference number. Replace this with the book's reference number that you wish to sell as the first book.

The next book, would have it's image saved as book2.gif, the code would be as follows:

    case 2:
        refno='123456789';
        bname='The Book\'s Title';
        break;

You would continue to add each book in the format above, remembering to increase the number which appears after the word case. If, for example, you had 5 books to sell, the last book would be entered as follows:

    case 5:
        refno='987654321';
        bname='My last book';
        break;

The last alteration to be made to the code is to tell the script how many books you are selling. You do this by altering the first line: mybooks = 4;.

Alter the number to the number of books you are selling to:

mybooks = 5;

if you were selling five books.

This article first appeared on Dynamic It!, therefore all enquiries for help should be directed to Ben Allen at script_man@hotmail.com

Related items

Macromedia Fireworks Image Map Tutorial

A JavaScript Picture Gallery

Speeding up image rollovers

Fading Images in and out

Controlling Images #2

Controlling Images

Image Maps

Toolbar Images

Random Banner Adverts

Highlighting Images (#2)

©2018 Martin Webb