Choose a location:
posted 6/3/2010 by Raghav Khunger
In this blog I will show you how to redirect to other URL or page with jQuery. To show it I have posted a sample code below. In this example I have used an input button, on clicking on that input button you will be redirected to external URL. Below is the source code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> </head> <body> <body> <input id="btnTest" type="button" value="Test" /> </body> <script type="text/javascript"> $('#btnTest').click(function () { $(window.location).attr('href', 'http://www.google.com'); }); </script> </html>
In the above example the heart of the code which is used to redirect to other URL is
$(window.location).attr('href', 'http://www.google.com');
I am just setting href attribute of window.location selector to 'http://www.google.com' which is the external URL. You can put your required URL there to achieve the same for you.
Do let me know your feedback, comments.
What kind of email newsletter would you prefer to receive from CodeAsp.Net? 18