Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Redirect to another page using Javascript

In html file to redirect a page using Javascript i used like this

window.location.href = "http://www.google.com/";

Its working fine. But when i tried in .aspx it is not working Below is my code. Thanks in advance

<head runat="server">
<script type="text/javascript">
   function PageRedirect() {
       window.location.href = "http://www.google.com/";
   }
 </script>
</head>
<body>
<form runat="server">
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="PageRedirect()"/>
  </form>
like image 609
Jagadesh Avatar asked Mar 06 '13 11:03

Jagadesh


People also ask

How do I redirect a page to another page?

How to Redirect to Another Page in HTML. To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

What is JavaScript 301 redirect?

“If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.”

How do you hit a URL in JavaScript?

To make an HTTP call in Ajax, you need to initialize a new XMLHttpRequest() method, specify the URL endpoint and HTTP method (in this case GET). Finally, we use the open() method to tie the HTTP method and URL endpoint together and call the send() method to fire off the request.


1 Answers

Try this:

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="PageRedirect(); return false;"/>
like image 183
karaxuna Avatar answered Nov 07 '22 03:11

karaxuna