Page redirection is essential for directing users from one URL to another. Learn how to implement different types of redirects using JavaScript:
Why Use Page Redirection?
- Migrating to a new domain without losing traffic.
- Routing users based on browser types or geographical locations.
- Maintaining SEO when restructuring URLs.
Examples of Page Redirection
Example 1: Instant Redirection
Redirect users immediately:
<script type="text/javascript"> window.location = "http://www.newlocation.com"; </script>
Example 2: Delayed Redirection with Message
Display a message and redirect after a delay:
<script type="text/javascript">
function Redirect() {
window.location = "http://www.newlocation.com";
}
document.write("Redirecting in 10 seconds...");
setTimeout('Redirect()', 10000);
</script>
Example 3: Redirect Based on Browser Type
Redirect users based on their browser type:
<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>
Comments
Post a Comment