jQuery redirect

How to redirect a page to URL with jQuery.

Search engines use the 301 status code to transfer the page rank from the old URL to the new URL.

jQuery redirection return http response status code: 200 OK.

So jQuery redirection, like Javascript redirection, is not search engine friendly and it is better to use other redirection methods that return status code of 301 Moved Permanently.

jQuery redirection is actually Javascript redirection. Redirecting with jQuery is considered overkill becuase you can do pure Javascript redirection with less code.

jQuery redirect

Replace old page with redirection code with the URL of the page you want to redirect to.

old-page.html:

<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
   // jQuery URL redirection
   $(document).ready( function() {
      url = "http://www.mydomain.com/new-page.html";
      $( location ).attr("href", url);
   });
</script>
</body>
</html>

jQuery redirect example

jquery-redirect-test.htm

<!DOCTYPE html>
<html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready( function() {
      url = "https://jobsvacancy.in/web/dev/jquery-redirect.htm";
      $(location).attr("href", url);
   });
</script>
</body>
</html>

 

Press this link to redirect from jquery-redirect-test.htm back to this page:

 

jQuery redirect test

 

 

Javascript redirection ►

 


See also

Write how to improve this page


email on- 00shivasharma@gmail.com
WEB DEVELOPMENT
RAPID TABLES