ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Tell Your Audience to Take a Hike
JAVASCRIPT --- 08/06/2002

David Wall

Traditionally, redirecting users to a new URL has been done in HTML. The META tag and its HTTP-EQUIV attribute can be used to move a browser along to another URL. If someone aims a browser at: 

On this topic

http://www.davidwall.com/

...and the index page contains the following tag (which isn't rendered by any but the most ancient and ignorant browsers) in its HEAD section:

<META HTTP-EQUIV="Refresh"
CONTENT="5;URL=http://www.purple-sage.com/">

...then the browser would redirect to the purple-sage.com URL after 5 seconds.

We can perform the same function with JavaScript as well. If you don't require a delay, simply include an onLoad event handler into the opening BODY tag:

<BODY onLoad="window.location.href = 'http://www.purple-sage.com/'">

If, however, you need a delay, things get a little more complicated. A function must handle a setTimeout() operation:

function redirect ()
{ setTimeout("window.location.href = 'http://www.purple-sage.com/'",10000); }

This function causes a 5000-millisecond (five-second) delay before the redirection takes place.

 

David Wall works as a freelance writer, programmer, lecturer, and consultant. Based near Washington, D.C., David has written and co- written several books, including Graphics Programming with JFC. David can be reached at David.Wall@itworld.com.



Advertisements
Sponsored links
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
Locate Hidden Software on business PCs with this free tool
 Home   Newsletters  JAVASCRIPT
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Industry Standard   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.