Home > Webmasters > Scripts > JavaScript Basics

JavaScript Basics

No major break throughs, here are simply the most commonly used JavaScripts.

Focus text field OnLoad
Step 1: Add the onLoad event handler to the BODY tag:

<BODY OnLoad="document.nameform.user.focus();">

Step 2: Add this code to the body of your HTML document:

<form name="nameform"> Name: <input type=text name=user size=10> </form>

History go back
Sends the visitors to the previously viewed page.
Add the below code inside the body, wherever you want the link to appear.

<a href="javascript:history.back()">Back to previous page</a>

Sends visitor back 2 pages:

<a href="javascript:history.go(-2)">Back 2 Pages</a>

To send them back even further, change the number inside the ()

Refresh Page
 
<a href="javascript:location.reload(1)">Refresh</a>

Close Window link
Copy this code into the BODY of your HTML document (wherever you want the link to appear):
 
<a href="javascript:window.close()">Close Window</a>

Print this page
Copy this code into the BODY of your HTML document (wherever you want the link to appear):

<a href="javascript:window.print()">Print This Page</a>
 
Automatic "break out of frames"
Copy this code into the BODY of your HTML document:
 
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (window != top) top.location.href = location.href;
// End -->
</SCRIPT>
Link to us!
Link to us If you find this site helpful, please help us spread the word by linking to us.
Help support this site:
Webmasters Internet ResourcesLink to us
Click here to bookmark PepFX.net!

Search PepFX.net

Search Help



Free Flash Guestbook