Javascript Redirect
Many of us have experienced redirection to another website. How? Well, remember when you clicked a link to reach a site, but you ended up in a different one? That is directing users to another page. This is something we often come across. This process is done through Javascript Redirect, and it is done with a couple of lines of code. It is a very common procedure for many websites.
Why Should You Redirect?
Time needed: 45 minutes.
You might want to redirect your user to another page from the one they intended for many different reasons.
- Removing duplicates
Your pages could be already indexed by search engines. That is why you do not want to lose visitors coming from them when you decide to switch to another domain. To prevent this, you can use the page redirection with Javascript. This is especially important regarding Search Engine Optimization. Website traffic is not easy to achieve, so you do not want to lose it just because you want to direct your visitors to a new page.
- Avoiding Seperate Server Redirection
You might have more than one page with different names according to different countries and browser types. In this case, you do not have to have separate server redirection.
- Changing domain name
You want to change your domain name and pass it on to a new one. If that is the case for you, then you probably want to redirect your users to your new site. This is achieved by keeping your old domain and insert a page that will redirect your previous domain visitors to the new one.

How Does Javascript Redirect Work?
There are many ways redirection could be done based on your preferences. While you are redirecting your visitors to a new page, you should consider the user-friendliness of the redirection process. You can have a button or tell the visitors that they are being redirected, so they do not get confused. Here are some examples.
This code will give you a redirect button:
Click the following button, you will be redirected to home page.
<html>
<head>
<script type = "text/javascript">
<!--
function Redirect() {
window.location = "https://www.tutorialspoint.com";
}
//-->
</script>
</head>
<body>
<p>Click the following button, you will be redirected to home page.</p>
<form>
<input type = "button" value = "Redirect Me" onclick = "Redirect();" />
</form>
</body>
</html>
2)With this example, you can tell your visitors that they will be directed to a new page in a few seconds.
<html>
<head>
<script type = "text/javascript">
<!--
function Redirect() {
window.location = "https://www.tutorialspoint.com";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);
//-->
</script>
</head>
<body>
</body>
</html>

One More Option
Lastly you can redirect your visitor baswed on different browsers using this code:
https://www.n11.com/urun/creality-ender-3-pro-3d-yazici-998282?<html>
<head>
<script type = "text/javascript">
<!--
var browsername = navigator.appName;
if( browsername == "Netscape" ) {
window.location = "http://www.location.com/ns.htm";
} else if ( browsername =="Microsoft Internet Explorer") {
window.location = "http://www.location.com/ie.htm";
} else {
window.location = "http://www.location.com/other.htm";
}
//-->
</script>
</head>
<body>
</body>
</html>
FAQ About Javascript Redirect
You can use “location.href”, “location.assign()” or “location.replace()” .
It is basically moving your visitors to another web page.
Not if you follow the correct steps.
The best thing you can do is use Javascript.
Yes, you can.
Conclusion on Javascript Redirect
No matter why you want to redirect your visitors to another page, you can easily do that with javascript by using certain snippets. In this article, you have learned what a redirect is and some examples of how to doa that. Want to learn more about redirecting? Here’s what is 301 redirect is.
The post Javascript Redirect is republished from Dopinger Blog
Yorumlar
Yorum Gönder