JAVA Script Tricks


JAVA Script can be a lot of fun to use. The following tricks are some of my favorites.

Link buttons - use, creation

If you run your mouse over the image, it changes. Cool, huh? I got this code from KatC's page. It was created by www.fractal.com. Use this code:

(place this part of the code before you close the <head> tag)
<script language="JavaScript"><!--
agent = navigator.userAgent;
browserVer = 2;
if (agent.substring(0,7) == "Mozilla")
{if (parseInt(agent.substring(8,9)) >= 3) {browserVer = 1;}}

// This JavaScript code originally developed by Fractal Design Corporation (http://www.fractal.com/)
// Reuse and repurposing is approved as long as the line above appears with the code

if (browserVer == 1) {
// one line for each image you will use
// replace image1 and image2 with your images
// (10,10) should be (width,height)
image1 = new Image(10,10);image1.src = "image.jpg";
image2 = new Image(10,10);image2.src = "image2.jpg";}

function hiLite(imgDocID,imgObjName) {
if (browserVer == 1) {
document.images[imgDocID].src = eval(imgObjName + ".src")}}
// --></script>

Place this part of the code anywhere on your page that you would like to use a link:
<A HREF="document.html" onMouseOver=hiLite('image','image2') onMouseOut=hiLite('image','image1')>
<IMG src="image.jpg" width=10 height=10 border=0 name=image></a>

Change the "image1.jpg" and "image2.jpg" to whatever your images happen to be.


More link tricks

If you have AOL or a similar browser, you might have noticed how I use a trick that lets me put text in the bottom bar. Use this code:

<a href="location.html" onmouseover="window.status='Cool, huh?'; return true">Text</a>

If you want the bottom bar to say something different if the viewer takes the mouse off the link, use this code:

<a href="location.html" onmouseover="window.status='Click Here!'; return true" onmouseout="window.status='I said click!'; return true">

If you don't want any text in the bottom bar after the viewer moves the mouse, use this code:

<a href="location.html" onmouseover="window.status='Cool, huh?'; return true" onmouseout="window.status=' ' ; return true">


Anti-theft protection

Don't want anyone to steal your images or codes? Use this piece of JAVA Script to prevent anyone from using the right-click on your page. Be warned- no one will be able to right click anywhere on the page you use it on. I recommend using this on thumbnail galleries. Right-click anywhere on this page to test the script.

<script language="JavaScript">

<!-- // No rightclick script v.2.5
// (c) 1998 barts1000
// barts1000@aol.com
// Don't delete this header!

var message="Anti-theft device is being used. The images and codes on this page are not for public use."; // Message for the alert box

// Don't edit below!

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN); }
document.onmousedown=click;
// -->
</script>

The only part you should edit is the "var message" section. Make it say whatever you would like it to say.


Pop-up buttons

I happen to hate pop-up buttons, but if you need to use one, here is the code:

<SCRIPT LANGUAGE="LiveScript">
<!--This script by Paul Tahan Jr-->
<!--
function checkAGE(){if (!confirm

("WRITE YOUR OWN MESSAGE IN HERE"))

history.go(-1);return " "}

document.writeln(checkAGE())
<!--End-->

</SCRIPT>

ONLY edit where it says "write your own message in here."


Drop-down menus

Use this drop-down JAVA menu instead of text to navigate your site

<center>
<script LANGUAGE="JavaScript">
/* This script is from Eric Blanchette bomuppet@yahoo.com
please feel free to use as long as you copy this copyright along with
the code
*/
<!--
function gotoURL() {
var Current = document.formName5.selectName5.selectedIndex;
location.href =
document.formName5.selectName5.options[Current].value;
return false;
}
//-->
</script>

<table>
<tr ALIGN="LEFT" VALIGN="TOP">
<td><form name="formName5">

<select NAME="selectName5" size="1">
<option>Where d'ya wanna go?</option>
<option VALUE="site1.html">Site 1</option>
<option VALUE="site2.html">Site 2</option>
<option VALUE="site3.html">Site 3</option>
<option VALUE="site4.html">Site 4</option>
<option VALUE="site5.html">Site 5</option>
<option VALUE="site6.html">Site 6</option>
<option VALUE="site7.html">Site 7</option>
<option VALUE="site8.html">Site 8</option>
<option VALUE="site9.html">Site 9</option>
<option VALUE="site10.html">Site 10</option>
</select><input name="submitName5" TYPE="SUBMIT" VALUE="I wanna go here!"
onClick="return gotoURL()">
</form> </td> </tr></table></center>

Adjust this to your liking. You don't need to use all 10 options, or you can use more. I got this code and the one above from www.javagoodies.com. Go there if you want to look around at more scripts.


Cute little quiz

Want the script for a quiz? This uses 10 questions - you make them up - and you can control which answer is right and which is wrong. I've set all the answers to A, but you can change them.

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Monichar -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var ans = new Array;
var done = new Array;
var score = 0;
ans[1] = "a";
ans[2] = "a";
ans[3] = "a";
ans[4] = "a";
ans[5] = "a";
ans[6] = "a";
ans[7] = "a";
ans[8] = "a";
ans[9] = "a";
ans[10] = "a";
function Engine(question, answer) {
if (answer != ans[question]) {
if (!done[question]) {
done[question] = -1;
alert("Wrong!\n\nYour score is now: " + score);
}
else {
alert("You have already answered that!");
}
}
else {
if (!done[question]) {
done[question] = -1;
score++;
alert("Correct!\n\nYour score is now: " + score);
}
else {
alert("You have already answered that!");
}
}
}

function NextLevel () {
if (score >= 10) {
alert("Wow! you got them all!");
}
if (score >= 7 && score <= 11) {
alert(self.location="next.html")
//
}
else {
alert("You need 7 points to move on.")
}}// End -->
</SCRIPT>

This script has 10 questions. If you get 7 right, you can move on to the next page. It can be another set of questions or just a congratulatory page or whatever. You can also change the message in the alert boxes to whatever you want - just don't touch the part that says + score or whatever.

 


Home
Back
Next Session
Contact Me