Friday 5 July 2013

jQuery Redirect to Another Page with Button Click in JavaScript

 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.


 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://paceinfonet.org';


$(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://paceinfonet.org';

$(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://paceinfonet.org';

window.location.href = url;



or



var url = 'http://paceinfonet.org';

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://paceinfonet.org';

window.location.href = url;

}

</script>

</body>

</html>


No comments:

Post a Comment