Methods to redirect URLs (HTML, PHP and Javascript)

CSS, XHTML/HTML & Javascript - Having trouble with CSS post your question here. Find solutions & discuss stylesheets, tutorials and techniques.
Post Reply
User avatar
romeo
Junior Member
Posts: 23
Joined: Tue Apr 28, 2015 9:24 pm

In this tip , I show you several methods to redirect URLs. That is, that when you enter a web page automatically sent to another.

Method 1. HTML

The first method is to use the element GOAL . Let syntax use for our purpose:

Code: Select all

<Meta  http-equiv = "action"  content = "seconds" ; url = "url destination"  />
Suppose you changed your server or you have moved a page to another directory. Show a message about it and are forwarding our user to the new page location. In this example, the action will "refresh" the time it takes to refresh the page shall be five (5) seconds:

Code: Select all

<Html> 
<head> 
<meta  http-equiv ="Refresh"  content ="5; url=http://www.blackhatboard.com" > 
</ head>

<Body> 
<p> We have moved! You will be automatically redirected in five seconds. Otherwise, you can access by clicking <a  href = "http://www.blackhatboard.com"> here </a> </ p> 
</ body> 
</ html>
Method 2. PHP

The following example will redirect the user without notice:

Code: Select all

<? php
header ( "Location: http://www.blackhatboard.com" ); 
>?
3. Method JavaScript

We can do with JavaScript , the methods previously seen. In the case of a redirect on hold, we must use a "timer". Here's an example:

Code: Select all

<html> 
<head> 
<script  type = "text/javascript" > 
function redireccionar (){ 
  window . locationf = "http://www.blackhatboard.com" ; 
}  
setTimeout ( "redireccionar()" ,  5000 );  //tiempo in milliseconds 
</ script> 
</ head> 
<body> 
<p> Please wait will be redirected in five seconds. </ p> 
</ body> 
</ html>
Making directly, without waiting:

Code: Select all

<Body> 
<script  type = "text / javascript" > 
window . location = "http://www.blackhatboard.com" ; 
</ script> 
</ body>
:)


Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest