Page Redirect Techniques - HTML and Javascript
Feb 12th, 2007 by Onyrix 506 Views |
Email This Post
|
Print This Post
There are 2 methods to redirect html pages.
The first one is pure HTML.
The second one is done with Javascript.
HTML Method
insert this line inside the
<head> … </head>
block:
<meta http-equiv=”refresh” content=”num_sec; URL=new_web_address”>
where
- num_sec is the number of seconds to wait before redirection
- new_web_address is the new relative or absolute URL where to go
Some (old) browsers do not interpret this meta so always remember to add a visual hyperlink to the same page where to redirect in some well visible portion of the page like this:
<a href=”new_web_address”>Click here if you are not automatically redirected to page num_sec before new_web_address seconds.</a>
Pro: it works even if Javascript is disabled
Vs: some old browsers do not interpret it
Javascript Method
If you want to redirect immediately to the new page, add this 5 lines after the <head> tag:
<script language=”javascript” type=”text/javascript”>
<!–
window.location=”new_web_address”;
// –>
</script>
If you want to redirect to the new page but only after the old page was displayed for at least num_sec seconds add this lines after the final </html> tag:
<script language=”javascript” type=”text/javascript”>
<!–
window.setTimeout(’window.location=”new_web_address”; ‘, num_sec*1000);
// –>
</script>

del.icio.us
Digg
Furl
Reddit
Technorati