|
JavaScript tips and common questions
Topics covered:
This section is listed as a series of Questions and Answers.
Question:
How do I run a JavaScript once a page is done loading?
Answer:
Your BODY tag must include an "onload" event with the function to run like this:
<BODY text="#FFFFFF" bgcolor="#000000" onLoad="pageLoaded()">
That example will call a function called pageLoaded() once the page has finished loading.
Question:
How do I use an external JavaScript (.js) file?
Answer:
You need to add the following to your HTML file (generally in the <HEAD>...</HEAD> section,
although it can be anywhere you would normally add the JavaScript to your HTML):
<SCRIPT language="JavaScript" src="filename.js" type="text/javascript">
In the example above replace filename.js with the actual name of the JavaScript file.
You may now call the functions in the .js file like you normally would if they were in your
HTML file.
Question:
How do I call two functions from the same onMouseOver event?
Answer:
All you have to do is follow each function that you want called with a semi-colon except the last
function (although following the last function with a semi-colon shouldn't cause any problems).
You can use this in any event (i.e. onMouseOver, onMouseOut, onLoad, etc.)
For example:
<A href="somepage.html" onMouseOver="dothis(); dothistoo()">The links name</A>
In the example above when a mouse goes over "The links name" the functions dothis() and dothistoo()
will both be called in that order.
|