iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Little Scripts Collection – Vol. 1 

  Views:    8915
  Votes:    6
by Ahmad Permessur 4/29/04 Rating: 

Synopsis:

This tutorial includes a collection of useful JavaScripts that surely will spice up your website.
Pages: 
The Article

Sometimes some little scripts can bring about magic to your site. This tutorial includes a collection of useful scripts that surely will spice up your pages. This article covers page redirection, displaying today’s date, closing window, setting page as ‘home page’ and adding page to ‘favorites’.


Page Redirection

Using JavaScript, it is possible to redirect viewers to a page instantly. Here’s the code, which must go in your <HEAD> section:

<HEAD>
<SCRIPT language="JavaScript">
<!--
window.location="
http://www.somewhere.com";
//-->
</SCRIPT>
</HEAD>
 

Today’s Date

Visitors are always confused and putting today’s date on your page will make life easier for them. Here’s the code:

<SCRIPT LANGUAGE = "JavaScript">
<!--

// Array of day names
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

var monthNames = new Array("January","February","March","April","May","June","July",
"August","September","October","November","December");

var dt = new Date();
var y = dt.getYear();

// Y2K compliant
if (y < 1000) y +=1900;

document.write(dayNames[dt.getDay()] + ", " + monthNames[dt.getMonth()] + " " + dt.getDate() + ", " + y);
// -->
</SCRIPT>


Closing Window

Very often we use pop-ups in our site and sometimes we disable the close button option. Providing the users with a close window option with JavaScript can be as simple as that:

<form>
<input type=button value="Close Window" onClick="javascript:window.close();">
</form>
or <a href="javascript:window.close();">Close Window</a>

Note that I have included the ‘close window’ function in 2 forms; a button and a link.

Setting your page as Home Page

Providing a ‘Make Home Page’ option to your site might encourage people to do that. It is possible to set this script to an onLoad event handler so that it happens as soon as the user logs into your page. A little box pops up once the script runs, asking if the user really wants your page set to be the home page. Don't make them click "no" every time they come in. Keep everyone happy and let them choose whether to set your page as their home page or not. Here's the code:

 
<SPAN
onClick="this.style.behavior='url(#default#homepage)';
this.setHomePage('http://www.edevcafe.com');">
Click Here to Make eDevCafe.com Your Home Page
</SPAN>
 

Note: You can change the cursor type, and text decoration colour and style.

Adding Page to Favorites

Ease your visitor’s journey by providing them a way to bookmark your URL. Here’s the code:

<U>
<SPAN STYLE='color:blue;cursor:hand;'
onClick='window.external.AddFavorite(location.href, document.title);'>
Add this page to your favorites
</U>
 
 

Note:
- window.external states that an external window will be called upon.
- AddFavorite does just what it says. It adds something to your favorites menu.
- location.href, document.title is what it adds, the page's URL and the document.title.

Pages: 

Similar/related articles:


 
  Sponsors