| runway index |
The Web TutorialsNew Window :: Browser Compatibility :: OnMouseOver :: OnMouseOut :: OnClick :: Further Resourses :: |
Chapter IndexIntroduction
|
Javascript is a programming language that was invented by Netscape, and is used extensively to program events within the browser windows. Thus, should you move your mouse over an item, you can program the browser to react in certain ways to that action, in short, you initiate an event within the browser window. There is a whole language to learn, but for the moment we will concern ourselves only with a few basic routines: Opening a New WindowUsually one seeks to open a new window by clicking on a link and that link being followed will cause the new page to load in the existing window. One can always seek to have it load in a new window by adding an extra parameter to the link code. Remember that adding a TARGET to the link reference will direct the new page wherever you choose, either to the same window, to a different frame, or to a new window. You may wish to order things slightly differently. You may wish to have a specifically sized window open to display some item from your own site, maybe a map, or just a short paragraph. You won't want to produce a whole page, and you may want to control whether this window has directory buttons, scrollbars, and the like. You can do all this with a simple piece of javascript code. In fact there are two ways you can do it. First, create a function, give that function a name, and then define it. All of this goes in the HEAD. Later in the BODY you can call that function. The code below is an example of the creation of the function in the HEAD of your page. Put it after the TITLE. First you tell the browser what language this is (JavaScript), and note the spelling and capitalisation. Then name your function. I have called this one "crackers()". I have defined it as a function which will open a new window containing the page 'crackers.html'. I have also defined how I want that window to display. You will note that all the accoutrements are in the 'off' position as we won't be needing the directory buttons and location bar, etc. I have allowed resizing and scrollbars, but have also defined the size of the window in pixels. Note the various quote marks, commas, semi-colons, and braces.
You will need to call this function somewhere in the body of the text. When you would normally use the HREF tag to open a new link you can instead call this JavaScript function:
When someone now clicks on the text "Jokes from Christmas crackers" the Javascript function will leap into action and open the new window that you have previously defined. A simpler way of doing this is to use the JavaScript command language. You need to use the 'Open' command. To show that it is a reserved command word we place a fullstop in front of the word open. Re-writing the above code we would not need to define the function in the HEAD of the page at all, but merely call the Open command in the BODY at the point at which we need to display our link in a new window. Thus the second part of the text in the previous example would be written as follows:
Note the so-called 'nowhere tag' after the HREF. The reference is calling the JavaScript command, not a URL. The JavaScript command then itself directs the browser to the correct URL. Having created a new window which does not look like the normal browser window, you will find it doesn't behave quite like the normal window either. It has a nasty habit of not closing when you leave it, and when you recall it you find nothing happens. The window is open, but underneath whichever other windows may also be open. |
OnMouseOver /OnMouseOutMove your mouse over an object on the page of a web site. If that object is a link, then the cursor will change into a hand, and a piece of text will be displayed in the Status bar at the bottom of the browser window. However, you can do more than that. You can write JavaScript code to perform many actions that you want to occur when the mouse is moved over the object. One of the more usual choices is to change images on a button when the mouse moves over it, to give the impression that the button is being depressed by the cursor. In order to create this effect you need to have created two images in the first place, one for the up state and one for the down state. The code to change one for the other as the cursor passes over it is as follows:
The original image is "links.gif". That image is given a name "link1". When the cursor moves over it the OnMouseOver instruction calls for the image to be swopped to "happy.gif". When the cursor moves off the image the OnMouseOut instruction calls for the image to be swopped back to the original. JiffyClip is a useful tool for creating JavaScript mouseovers. Check it out. OnClickWe can add a further piece of code to make something else happen. When the cursor is over the image, which has now changed, the mouse can be clicked to activate a link to another page. The complete set of code looks like this:
Here I have sewn together all the pieces of code, so that on the click of the mouse (onClick) a new specially defined window is opened containing another page. Do remember to put the function in the HEAD of your document. You are calling the function "swapImage". You must define it.
ResourcesCheck out the following sites for surther help, and scripts:
|
|
|
|
|
© John Clare. runway 1999