How to redirect domain to another domain, when the first domain (webpage) load?
+2
A:
There are a couple of ways to do this. One is to add the an onload event to the body tag what sets window.location to the new domain.
<script language=javascript>
function redirect(){
window.location = "http://newurl";
}
</script>
<body onload="redirect()">
</body>
Barlow Tucker
2010-08-10 15:05:39
A lot more efficient to use the ASP.NET redirect header approach, but this will certainly work. (As long as JavaScript is enabled.)
middaparka
2010-08-10 15:12:06
Agreed. Depending on the server setup, there could be a redirect on the web server level as well. BalusC has a good solution as well.
Barlow Tucker
2010-08-10 15:26:34
+1
A:
A pure HTML alternative is the following <meta>
tag in your HTML <head>
:
<meta http-equiv="refresh" content="0;http://anotherdomain.com">
The 0
is here the amount of seconds the page has to stay open before redirecting. In this case, it'll happen immediately as soon as you loads the page. In contrary to the proposed JS solution, this will work fine as well in browsers with JS disabled.
However, if you've the ability to hook on server side code without trouble (i.e. response is not committed yet and so on), then I'd prefer that above the HTML/JS solution anyway.
BalusC
2010-08-10 15:15:13