There are many ways to redirect a page to another page using javascript. And this is very simple to use and understand. I present some of these function to redirect a page to another page.
1. Using Meta Tag
You can redirect a page to another page using meta tag. You can also set time. For example you set time 5. That means your page is redirect to another page after 5 seconds.
See example code
[sourcecode]
<html>
<head>
<title>Javascript Tricks</title>
<META http-equiv="refresh" content="5;URL=https://www.facebook.com/">
</head>
<body>
<p>Javascript example</p>
</body>
</html>
[/sourcecode]
2. Using Javascript Function
Second way is to redirect a page to another page using javascript function window.location
See example code
[sourcecode]
<html>
<head>
<script type="text/javascript">
function Redirect()
{
window.location="https://www.facebook.com/";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout(‘Redirect()’, 10000);
</script>
</head>
</html>
[/sourcecode]
3. Using window.open
You can also use window.open() to redirect a page to another page.
See example code
[sourcecode]
<html>
<head>
<script type="text/javascript">
function myCustomHref() { window.open (‘https://www.facebook.com/’, ‘_self’); }
</script>
</head>
<body>
<a onclick="myCustomHref();">click</a>
</body>
</html>
[/sourcecode]
4. Using window.location.assign
Let’s see following example to understand how to redirect a page to another page using window.location.assign.
See example code
[sourcecode]
<html>
<head>
<script type="text/javascript">
function newPage() {
window.location.assign("https://www.facebook.com/")
}
</script>
</head>
<body>
<a onclick="newPage();">click</a>
</body>
</html>
[/sourcecode]