JavaScript Page Redirect

We can redirect users or browser to a different page or url by using JavaScript. This page uses client side script of client so script execution must be enabled in the browser.

If in browser script execution is disabled then JavaScript (Client side) page redirection won't work. You can check the status of script execution of browser and accordingly warn the users.

We will try first with some simple page redirect example and then we will add different features to it.

<script language='JavaScript' type='text/JavaScript'>
<!--
window.location="http://www.google.com";
//-->
</script>
You can also redirect by using slef.location like this
self.location='http://www.google.com'

Redirecting after Some time delay

If you are using the above code then the page will redirect to google.com as soon as the page loads to client browser. Here we can delay the process of redirection and show a message. We will be using our timer function to do this. Here is the code.

<html>
<head>
<title>Javascript page redirect</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
setTimeout('window.location="http://www.google.com"',10000)

//-->
</script>
</head>
<body>
You will be reirected to google after 10 Secs

</body>
</html>
Try to add one count down display to show seconds left for page redirect to work.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

sdaf

05-07-2010

Nice tutorial Great.

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer