HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings

Web Stuff | Audio | Basics | Browser | Code Tips | Design | Fonts | Forms | Frames (Page 1), (Page 2) | Images (Page 1), (Page 2) | Links | Random | Redirection | Sound | Video | Search Engines | Lycos UK | Home Server (Page 1), (Page 2), (Page 3)

When copying the code from these pages remember to paste them first into a text only editor such as Notepad and then copy and paste from there into your webpage. This is so that all the text formatting codes can be removed from the copied text. Remember that your HTML editor must be in code or HTML view when you paste the code into it. If you are using a template driven HTML editor then the code must be pasted into an HTML and not a text box. JavaScript must be enabled in your browser for the effects generated by it to be seen.

Redirecting Web Pages :-

It is sometimes extremely useful to redirect your visitors from one page to another. You may have redesigned your pages, or entire site. You may have even moved your site to a new host or server.

The advantage of using a redirect script is that your visitors aren't faced with a obsolete page and can be moved to the new page without taking any further action. The disadvantage is that some search engines do not like redirect scripts at all, and may downgrade your page rank.

The main script to redirect a page is a simple meta tag and takes the form...

<META HTTP-EQUIV="Refresh" CONTENT="time_in_seconds; URL=URL_to_redirect_to">

time_in_seconds can be any value you like. A value of 0 will cause immediate redirection.

The code on the demonstration page is...

<META HTTP-EQUIV="Refresh" CONTENT="10; URL=wredir1.htm">

It will be beneficial to your visitors if you put some sort of text on the page to explain why they are being redirected. It also helps if you put a HTML link on the page and the URL of the page they are being redirected to. The HTML link will help search engines find your new page and the URL will help people who have automatic redirection in their browsers turned off.

You can also put a button on your page like the one below.

The code for the button is...

<p align="center"><input type="button" value="Go to new URL" name="btnNewURL" onclick=location.replace("URL_to_go_to");></p>

The code on the demonstration page is...

<p align="center"><input type="button" value="Return to page" name="btnNewURL" onclick=location.replace("wredir1.htm");></p>

Notice the part onclick=location.replace("URL_to_go_to") What this does is to actually replace the old URL (the page the code was on) with the new URL in the browser history. What this means is that when the user clicks the back button they do not go back to the old page but they go to the page the visited before it. This piece of code can be used to replace location.href("URL_to_go_to"). That particular tip comes from Cre8asite.

View a demonstration of the above codes

The are other methods of causing a redirection to another page.

To cause an automatic immediate redirection put the following into the HEAD section of the old page...

<SCRIPT language="JavaScript">
<!-- Hide from old browsers
window.location.replace("URL_to_go_to");
// Stop hiding -->
</SCRIPT>

The code on the demonstration page is...

<SCRIPT language="JavaScript">
<!-- Hide from old browsers
window.location.replace("wredir1.htm");
// Stop hiding -->
</SCRIPT>

View a demonstration of the above code

You can always use a timer with the redirection. To do this, put the following code into the HEAD of your old page...

<SCRIPT language="JavaScript">
<!-- Hide from old browsers
setTimeout( "window.location.replace='URL_to_go_to'",time_in_thousandths_of_seconds);
// Stop hiding -->
</SCRIPT>

JavaScript timers use thousandths of a second, so 10000 would be 10 seconds.

The code on the demonstration page is...

<SCRIPT language="JavaScript">
<!-- Hide from old browsers
setTimeout( "window.location.replace='wredir1.htm'",10000);
// Stop hiding -->
</SCRIPT>

View a demonstration of the above code
 

Web Stuff | Audio | Basics | Browser | Code Tips | Design | Fonts | Forms | Frames (Page 1), (Page 2) | Images (Page 1), (Page 2) | Links | Random | Redirection | Sound | Video | Search Engines | Lycos UK | Home Server (Page 1), (Page 2), (Page 3)

HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings

This page created 1st December 2003, last modified 28th December 2004.


GoStats stats counter