是否可以设置一个基本的HTML页面以在加载时重定向到另一个页面?


当前回答

适用于所有类型页面的简单方法是在头部添加一个元标记:

<html>
    <head>
        ...
        <meta HTTP-EQUIV="REFRESH" content="seconds; url=your.full.url/path/filename">
        ...
    </head>
    <body>
        Don't put much content, just some text and an anchor.
        Actually, you will be redirected in N seconds (as specified in content attribute).
        That's all.
        ...
    </body>
</html>

其他回答

只需使用body标签的onload事件:

<body onload="window.location = 'http://example.com/'">

我还将添加一个规范链接来帮助您的SEO人员:

<link rel="canonical" href="http://www.example.com/product.php?item=swedish-fish"/>

一旦页面加载,init函数就会启动并重定向页面:

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
        <script>
            function init()
            {
               window.location.href = "www.wherever.com";
            }
        </script>
    </head>

    <body onload="init()">
    </body>
</html>

这不需要任何JavaScript代码。将其写入HTML页面的<head>部分:

<meta http-equiv="refresh" content="0; url=example.com" />

页面在0秒加载后,即可转到页面。

在HTML代码的<HEAD>和</HEAD>标记之间放置以下代码:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://example.com/index.html">

上述HTML重定向代码将立即将访问者重定向到另一个网页。content=“0;可以更改为您希望浏览器在重定向之前等待的秒数。