CodeBodger's
Home


Overview

Examples

Instructions

Script Maker

Sample
Single-Image
Page


Code
Discussion


Better Thumbnail Links
Code Discussion

The Onclick Handler

This may seen needlessly complex - but it copes with framed and non-framed pages, saving a lot of confusion for those not familiar with Javascript.
It also means that I can archive it without keeping two versions!

var Caller=self;
This saves a reference to the calling page so that the function can replace the original page without having to be told specifically where the page is. You cannot use self in the function arguments as when the function is called, self will refer to the page the script is embedded in. This may be the calling page or the frameset page.

with (parent)
This adds the parent frameset to the current scope. For a non-framed page this does nothing as self=parent. If a frameset exists, the function is looked for in the frameset, and if it is not found, the current page is checked.

if (typeof(FunctionName)!='undefined')
If it all goes wrong, and the function cannot be found, returns void so the standard link can be followed.
If the function is found, false is returned to prevent the standard link being followed.
This prevents error messages that look so unprofessional!

The Main Function

var BackURL = Caller.location.href;
This saves the location of the calling page so that the BackURL link can be inserted. If this is not saved, the location will change as soon as the document is opened by the function.

with (Caller.document)
Really just saves typing it out in front of every write('...
Remember Caller is a reference to the calling page, so the correct page always gets replaced.

The rest of the function is just a standard open page, write to it and close it.