Redirect from an HTML page

2018-12-31 02:58发布

Is it possible to set up a basic HTML page to redirect to another page on load?

25条回答
后来的你喜欢了谁
2楼-- · 2018-12-31 03:13

I use a script which redirects the user from index.html to Login Page

<html>
  <head>
    <title>index.html</title>
  </head>
  <body onload="document.getElementById('lnkhome').click();">
    <a href="/Pages/Login.aspx" id="lnkhome">Go to Login Page<a>
  </body>
</html>
查看更多
姐姐魅力值爆表
3楼-- · 2018-12-31 03:14

This is a sum up of every previous answers plus an additional solution using HTTP Refresh Header via .htaccess

1. HTTP Refresh Header

First of all, you can use .htaccess to set a refresh header like this

Header set Refresh "3"

This is the "static" equivalent of using the header() function in PHP

header("refresh: 3;");

Note that this solution is not supported by every browser.

2. JavaScript

With an alternate URL:

<script>
    setTimeout(function(){location.href="http://example.com/alternate_url.html"} , 3000);
</script>

Without an alternate URL:

<script>
    setTimeout("location.reload(true);",timeoutPeriod);
</script>

Via jQuery:

<script>
    window.location.reload(true);
</script>

3. Meta Refresh

You can use meta refresh when dependencies on JavaScript and redirect headers are unwanted

With an alternate URL:

<meta http-equiv="Refresh" content="3; url=http://example.com/alternate_url.html">

Without an alternate URL:

<meta http-equiv="Refresh" content="3">

Using <noscript>:

<noscript>
    <meta http-equiv="refresh" content="3" />
</noscript>

Optionally

As recommended by Billy Moon, you can provide a refresh link in case something goes wrong:

If you are not redirected automatically: <a href='http://example.com/alternat_url.html'>Click here</a>

Resources

查看更多
若你有天会懂
4楼-- · 2018-12-31 03:15

The following meta tag, placed between inside the head, will tell the browser to redirect:

<meta http-equiv="Refresh" content="seconds; url=URL"> 

Replace seconds with the number of seconds to wait before it redirects, and replace URL with the URL you want it to redirect to.

Alternatively, you can redirect with JavaScript. Place this inside of a script tag anywhere on the page:

window.location = "URL"
查看更多
刘海飞了
5楼-- · 2018-12-31 03:15

Just for good measure:

<?php
header("Location: example@example.com", TRUE, 303);
exit;
?>

Make sure there are no echo's above the script otherwise it will be ignored. http://php.net/manual/en/function.header.php

查看更多
千与千寻千般痛.
6楼-- · 2018-12-31 03:16

Place the following code between the <HEAD> and </HEAD> tags of your HTML code:

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

The above HTML redirect code will redirect your visitors to another web page instantly. The content="0; may be changed to the number of seconds you want the browser to wait before redirecting.

查看更多
只靠听说
7楼-- · 2018-12-31 03:19

JavaScript

<script language="javascript">
    window.location.href = "http://example.com"
</script>

Meta tag

<meta http-equiv="refresh" content="0;url=http://example.com">
查看更多
登录 后发表回答