Borrowing JavaScripts

The Script


JavaScripts are always located within script tags and script comment tags. Often the scripts are located in the head section of the HTML document, but they can also be inside the body tags. (<body>..</body>) A basic script might look like this:


<script language=javascript>
<!--
function scrollit(seit)
{

var m1 = "First Section Of Your Message . . .";
var m2 = " . . . Second Section Of Your Message. . .";
var m3 = " . . . Third Section Of Your Message d . . .";
var m4 = " . . . Last Section Of Your Message . . .";
var msg=m1+m2+m3+m4;
more code could go here.........
}
//-->
</script>



What you find between the <script> tags is the script itself. If the script is FREE, it could all be copied into your web page. It would be best if you place it in the same section of your page that you found it in the other page Be careful of copyright infringement. Imagine if you worked for hours and hours perfecting a script and someone just decided to cut and paste it. Give credit where credit is due.


The Event

You will also need to find that which causes the script to run. This component is called an event handler.
Events are located within some tag - usually in <body>, or <a href= ?> tags - and specify when and why the browser should execute a series of commands. Here is a reliable way to locate the right event handler. First look for the function that contains the script.

See the part that says function scrollit(seit)? It looks like this:


<script language=javascript>
<!--
function scrollit(seit){

var m1 = "First Section Of Your Message . . .";
var m2 = " . . . Second Section Of Your Message. . .";
var m3 = " . . . Third Section Of Your Message d . . .";
var m4 = " . . . Last Section Of Your Message . . .";
var msg=m1+m2+m3+m4;
MORE STUFF.........
}
//-->
</script>


scrollit(seit) is the function name.
Once you find the function name in the script, go to the body of the page you are borrowing from and look inside the tags - usually body, input, or href tags - for something that looks like "onSomeEvent=functionName(xxxx)". In the case of the script that we are borrowing right now, the event is located in the body tag. It looks like this:


<body bgcolor=ffffff onLoad=scrollit(100)>

All event handlers begin with "on"


Copyright Infringement

You should never just take a script without asking. It is always a good idea to ask permission to use a script from the script owner.

Often, information regarding allowable usage, persons to contact in order to request permission, or other copyright-type information is included in the script itself (often in the head) and is commented out.




Customizing the Script

Customizing is pretty simple. Look through the script itself until you find the text that you want to change and replace it with whatever you want to use.

SURF FAST.com