JavaScript

Page 2

Some Scripting that come in handy:

The little script below come in handy at the end of each year when it becomes necessary to update the dates at the bottom of the pages.  It does it for you without worry or hassle.

<script language="JavaScript">
copyright=new Date();
update=copyright.getYear();

document.write("Copyright 2003-"+ update + " (Your Name)<br> All rights Reserved.");
</script>
Random Image/Link

Want to randomly display images and hyperlinks from a list? No problem, you can do it with a simple script like the one shown here. No need to learn server-side scripting, or slow down your pages with full-blown Java applications. The script shown below randomly loads an image from the list you input each time a page is loaded into a browser. This example works with two images. You can add as many as you like. You can even add the same image twice to double its weighting. For example, if you have two images and would like one to be shown twice as much as the other one, simply add the preferred image twice (to total three images in all).

Here?s the Script Code. All you have to do is replace the variable " imagenumber" with the correct amount of images you?re using. Be sure to label each image with its corresponding number in the images array. Then do the same for the corresponding links. You can also control your image attributes in the display portion of this script, which begins with 
" document.write"

That?s it. Load in your info, refresh the page and watch what happens!
<SCRIPT LANGUAGE="JavaScript"> 
<!-- Hide 
var imagenumber = 2 ; 
var randomnumber = Math.random() ; 
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ; 
images = new Array 
images[1] = "Directory/First_Image_Name.jpg" 
images[2] = "Directory/Second_Image_Name.jpg" 
var myimage = images[rand1] 
links = new Array 
links[1] = "Directory/Your_Page.html" 
links[2] = "Directory/Your_Page.html" 
var mylink = links[rand1] 
document.write('<A HREF="' + mylink + '"><IMG src="' + myimage + '"></A>') 
// -- End Hiding --> 
</SCRIPT> 

<a href="http://your target url goes here" title="write your description of the link here">Click here</a>
Automatic Bookmarking

Have you ever seen a button or text link on a site that lets visitors automatically bookmark a site? It's a simple procedure if you have the right tools, so let's get started. First off, for anyone who doesn't know, bookmarks or favorites are sites that have been stored by the user for quick retrieval. Bookmarks are usually made by selecting that option on your browser. But you can automate this process and (hopefully) incite your visitors to bookmark your site with a simple mouse-click. Here's how it can be done.

We use the following JavaScript to perform these actions. The first variable (bookmarkurl) is the URL to the site, while the second variable (bookmarktitle) is the actual pre-coded entry that the browser will display.

Place this script in the HEAD Section of your Page:
<script language="JavaScript1.2"> 
<!-- Start 
var bookmarkurl="http://www.bravenet.com/" 
var bookmarktitle="Bravenet.com - Free Tools for Webmasters" 
function addbookmark(){if 
(document.all)window.external.AddFavorite(bookmarkurl,bookmarktitle)}
// End -->
</script>

Now we call the script to actually place the link. This second part of our script should be placed exactly where you want the link to display:

<script language="JavaScript">
if (document.all)document.write('<a 
href="javascript:addbookmark()">&nbsp;Bookmark Now!</a>')
</script>

NOTE: The above script works only in Internet Explorer. If you want Netscape users to bookmark, you'll have to do something a little differently. Here's a solution provided by a Bravenet Member (thanks Youself!). This script places a text message in place of the bookmark link for Netscape users. This is a tidy script you can place in one spot, where you want the link (or message) to appear.

<SCRIPT language="JavaScript">
<!-- Begin 
<!-- Script By Yousuf Imtiaz-->
if (document.all) { // Only true for MSIE 
var url="http://www.yoursite.com"; 
var title="Bravenet.com - Free Tools for Webmasters"; 
document.write('<A HREF="javascript:window.ext'); 
document.write('ernal.AddFavorite(url,title);" '); 
document.write('onMouseOver=" window.status='); 
document.write("'Bookmark Now!'; return true "); 
document.write('"onMouseOut=" window.status='); 
document.write("' '; return true "); 
document.write('">Bookmark Now!</a>'); 
}
else {
document.write("Bookmark Now! (CTRL+D)");
}
// End -->
</SCRIPT>

Current Date
Looking for an easy way to add the current date to a page? Look no further.

Here?s a very simple JavaScript that you can use to display the date as 
determined by the user?s browser. The first variable can be changed to alter the way the month is displayed. In this example they are shortened to reduce the amount of space required. You can edit these to display the full month 
name if you like. If you use this script, remember you'll have to change the 
year come January 2001...

<SCRIPT LANGUAGE="JavaScript">
var monthNames = new Array( 
"Jan.","Feb.","March","April","May","June","July","August","Sept.","Oct.","Nov 
.","Dec."); 
var now = new Date(); 
document.write(monthNames[now.getMonth()] + " " + now.getDate() + ", " + 
2000);
</SCRIPT>

[ JavaScripts 1 | JavaScripts 2 | JavaScripts 3 | JavaScripts 4 | JavaScripts 5 | JavaScripts 6 ]

  

[ About Me | Site Legal Info | Site Design | CSS Coding ]
[ JavaScripts | Hints & Tips | BackGrounds | Misc. Images ]
[ Templates | Logo Page | Special Characters | Color Chart ]
[ Contact Us! | Awards Won | Links ]
[ Home | Site Map ]

 

Go to Top


Webmaster & Owner: Anita Eberline
No part may be reproduced without prior permission by Anita Eberline