HTML 页面如何在页面加载时重定向跳转到另一个页面,现在有两种方法,一种是通过标签页的 meta 标签实现页面重定向,另一种是使用avaScript实现页面重定向。
meta 标签跳转重定向
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="1;url=https://xxccc.cc">
</head>
<body>
<p>页面将在1秒钟后自动跳转到<a href="xxccc.cc">https://xxccc.cc</a></p>
</body>
</html>
设置 <meta>标签的 http-equiv属性为”refresh”,并设置 content属性的值为”1;url=xxccc.cc”,既实现了页面跳转,也可以直接将 content属性的值为”0, 删除
JavaScript 跳转重定向
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
window.location.href = "https://xxccc.cc";
};
</script>
</head>
<body>
<p>页面加载后将自动跳转到<a href="https://xxccc.cc">https://xxccc.cc</a></p>
</body>
</html>
通过将页面的 window.onload事件设置为一个函数,在函数中使用 window.location.href将页面重定向到目标URL。这种方法更加灵活地控制页面的跳转,适用于更复杂的重定向跳转需求。