Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect from one URL to another URL?

How can I redirect to another URL in a web page using JavaScript?

like image 706
User Avatar asked Jan 11 '12 17:01

User


People also ask

Can I redirect from one website to another?

When you redirect a URL, you're simply forwarding it to another address on the same, or different domain. You can set up a redirect that sends visitors to your new domain name when they'll try to access a URL that belonged to your old domain.


2 Answers

window.location.href = "URL2" 

inside a JS block on the page or in an included file; that's assuming you really want to do it on the client. Usually, the server sends the redirect via a 300-series response.

like image 198
Paul Avatar answered Oct 11 '22 18:10

Paul


Since you tagged the question with javascript and html...

For a purely HTML solution, you can use a meta tag in the header to "refresh" the page, specifying a different URL:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/somepage.html"> 

If you can/want to use JavaScript, you can set the location.href of the window:

<script type="text/javascript">     window.location.href = "http://www.yourdomain.com/somepage.html"; </script> 
like image 37
David Avatar answered Oct 11 '22 19:10

David