Redirect to a different page using jQuery in Asp.Net

This jQuery tutorial explains, how to redirect to a different page using jQuery in asp.net. We will also see, how to redirect to different pages onChange in a dropdown list using JavaScript.

Redirect to different page using jQuery

We can redirect to a different page by using window.location.replace(“”);

Below is the jQuery code, once you will run the page it will redirect to http://www.sharepointsky.com page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default14.aspx.cs" Inherits="Default14″ %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1″ runat="server">
<title>Redirect to different page using jQuery</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
window.location.replace(“http://www.sharepointsky.com");
});
</script>
</head>
<body>
<form id="form1″ runat="server">
<div>
</div>
</form>
</body>
</html>

Redirect to different page onChange in dropdownlist using JavaScript

Here my requirement is I have a dropdown list which contains different values. Whenever user select an option from the dropdown then the user should directly redirect to that page. I had a requirement to put some functionality like this in one of my SharePoint page.

So I edited the page and added a script editor webpart and in that web part I added the below code.

Below is the full code:

<select onChange="window.location.href=this.value">
<option value='none' selected>Please Select WebSite...</option>
<option value="https://www.enjoysharepoint.com">EnjoySharePoint.com</option>
<option value="http://www.SharePointSky.com">SharePointSky.com</option>
<option value="http://www.tsinfotechnologies.com">TSInfotechnologies.com</option>
</select>

Now whatever option you select it will go to the corresponding page.

Redirect users to different web site in Asp.Net using JavaScript

Now, we will discuss how to redirect users to different websites in Asp.Net using JavaScript.

In some situations, you need to redirect users to a different website. In the below example whenever a user opens the page, he will redirect to www.aspdotnethelp.com.

Below is the JavaScript code to redirect users to a different web site in Asp.Net.

<head runat="server">
<title>Redirect users to different web site in Asp.Net using JavaScript</title>
<script type="text/javascript">
location.replace(“https://www.enjoysharepoint.com");
</script>
</head>

You may like following javascript and jquery tutorials:

This tutorial we learned how to redirect to a different page using jQuery and how to redirect to different pages onChange in a dropdown list using JavaScript.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>