| <html> <head> <script language=javascript> <!-- Hide from older browsers function winBob( ) {window.open('winbob.html','bob','width=450,height=180') } // End hiding --> </script> </head> <body> <a href="5newwin.html" onClick="winBob( )">1</A> Bob Scott Campground </body> </html> |
This is another script which uses the "onClick" event handler. In this case, "onClick" is connected to a link rather than a button. "onClick" triggers a user-defined function which has been stored in the <head> portion of the html document.
JavaScript Functions
A function is a set of Javascript commands or statements that the user
can create and store for future use. Functions are given a name - e.g.
This is the general syntax used to create a function:
function myFunction( ) { javascript statement;
javascript statement;
etc......; }
In the New Window script example, the code could have just as easily
been written as a single line to be placed within the <a href> tag:
However, often a function is reused several times within an html
document. (The next demo illustrates a function that is used for more
than one purpose).
More About Opening New Windows
The generic JavaScript code for opening a new window is:
Some common window properties include width, height, scrollbars,
resizable, location and toolbar. Desired properties are strung together
separated only by commas (no spaces!). For example, a set of properties
might look like this:
'width=300px,height=100px,scrollbars=yes,resizable=yes,toolbar=no'