301 redirect using javascript?

netian
netian used Ask the Experts™
on
Hi,
How can i do a 301 redirect using Javascript?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
Although I do not recommend you using javascript to do a redirect. Nevertheless, here's the code.

I did not use the meta refresh tag because it is plainly not for this purpose.

<html>
<head>
<script type="text/javascript">
window.location.href='http://www.somacon.com/';
</script>
</head>
<body>
This page has moved to <a href="http://somacon.com/">http://somacon.com/</a>
 
</body>
</html>

Open in new window

Top Expert 2009

Commented:
Just in case you want to read up more. You can read more about redirecting in this article.
http://www.somacon.com/p145.php

Yes this code snippet is copied from there.
Top Expert 2009
Commented:
I forgot to add something, if you want the http status code 301 to be returned with javascript, it's not possible as described in the article.

Author

Commented:
Thanks TanliHao. I think using javascript its not possible to do 301 redirect. :(

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial