简体   繁体   English

如何将网页从一个域重定向到另一个域?

[英]How to redirect webpage from one domain to another?

当第一个域(网页)加载时,如何将域重定向到另一个域?

A pure HTML alternative is the following <meta> tag in your HTML <head> : 纯HTML替代方法是HTML <head>的以下<meta>标记:

<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. 0表示在重定向之前页面必须保持打开的秒数。 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. 与提议的JS解决方案相反,在禁用JS的浏览器中,这也可以正常工作。

However, if you've the ability to hook on server side code without trouble (ie response is not committed yet and so on), then I'd prefer that above the HTML/JS solution anyway. 但是,如果您能够毫无困难地挂接服务器端代码(即响应尚未提交等等),那么无论如何我都希望在HTML / JS解决方案之上。

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. 一种是将onload事件添加到body标记,将window.location设置为新域。

<script language=javascript>
function redirect(){
  window.location = "http://example.com";
}
</script>

<body onload="redirect()">

</body>
<% Response.Redirect ("http://example.com") %>

请参阅此处获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM