Introduction:
Here I will explain simple jQuery
code to redirect user to another web page using jQuery
and JavaScript. By using location object in jQuery
or JavaScript we can redirect user to another web page.
Description:
In previous articles I explained jQuery get set text to label, Get set asp.net control values in jQuery, jQuery Set Get textbox control value, jQuery get dropdown selected value & text, JavaScript create watermark text for textbox and many code snippets articles relating to JQuery,
JavaScript, asp.net.
Now I will explain how redirect user to another web page in jQuery
and JavaScript.
Redirect
User to Another web page using jQuery
To redirect user to another web page in jQuery
we need to write the code like as shown below
var url = 'http://www.aspdotnet-suresh.com';
$(location).attr('href', url);
|
Example
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
</head>
<body>
<input type="button" id="btnclick" value="Redirect" />
<script type="text/javascript">
$(function()
{
$("#btnclick").click(function() {
var url = 'http://www.aspdotnet-suresh.com';
$(location).attr('href',
url);
})
});
</script>
</body>
</html>
|
Redirect
User to Another web page in jQuery
To redirect user to another web page in JavaScript
we need to write the code like as shown below
var url = 'http://www.aspdotnet-suresh.com';
window.location.href
= url;
|
Or
var url = 'http://www.aspdotnet-suresh.com';
window.location
= url;
|
Example
<html>
<head>
</head>
<body>
<input type="button" id="btnclick" value="Redirect" onclick="RedirectSample()" />
<script type="text/javascript">
function RedirectSample() {
var url = 'http://www.aspdotnet-suresh.com';
window.location.href = url;
}
</script>
</body>
</html>
|
In this way we can redirect user to another web page
using jQuery or JavaScript
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
10 comments :
Sir , This is abhinavsingh993 It is a great article
Great Article
very good article.
sir i want to apply tagging for images in asp.net.Please help me sir
testing
Sir, This Abhinavsingh993 very good article sir.
Hi suresh,
Here what is difference between window.location.href = url; and
window.location = url; and
var url = 'http://www.aspdotnet-suresh.com';
$(location).attr('href', url);
Thanks Suresh u make me understand ASP.NET.
u r my Tutor. i think u'll help me in future to solve my problem. once again heartfull thanks
Amit Kr Singh
Nice tips you share. It is very useful.
dfghgjk
Note: Only a member of this blog may post a comment.