Introduction:
In this article I will explain how to redirect user to
another web page using jQuery or JavaScript.
By using location object in jQuery or JavaScript we can redirect user to another web
page.
1.
Redirect another
web page using jQuery :
Following
code is used for redirect user to other webpage:
<script type="text/javascript">
$(function() {
$("#btnclick").click(function()
{
var url = 'http://www.maziksolutions.com';
$(location).attr('href', url);
})
});
</script>
Full Source code for Sample
Webpage:
<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.maziksolutions.com';
$(location).attr('href', url);
})
});
</script>
</body>
</html>
2. Redirect another web page using JavaScript
To redirect user to another web page in JavaScript we need to write the code like as given below
<script type="text/javascript">
function RedirectSample() {
var url = 'http://www.maziksolutions.com';
window.location.href = url;
}
</script>
Full Source code for Sample
Webpage:
<html>
<html>
<head>
</head>
<body>
<input type="button" id="btnclick" value="Redirect" onclick="Redirect ()" />
<script type="text/javascript">
function Redirect () {
var url = 'http://maziksolutions.com';
window.location.href = url;
}
</script>
</body>
</html>
0 comments:
Post a Comment