web html网页开发的时候我们经常用到html页面自动跳转, 常用的跳转方式有2种一种是通过html的meta标签刷新, 另外一种是通过JS代码。 meta方式可用于无JS支持的页面自动跳转,优先级低于JS的跳转方式。
meta标签刷新自动跳转
核心代码就是在head之间加入代码 <meta http-equiv="refresh" content="0;url=你要跳转到的URL地址"> 即可
完整示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading......</title>
<meta http-equiv="refresh" content="0;url=https://dev.tekin.cn/?ref=csdn">
</head>
<body style="margin:0;background-color:black">
</body>
</html>
js window.location方式跳转
在head之间插入JS代码 <script language="javascript" type="text/javascript">
window.location.href="你要跳转到的URL地址";</script>
完整示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading......</title>
<script language="javascript" type="text/javascript">
window.location.href="https://dev.tekin.cn?ref=csdn";
</script>
</head>
<body style="margin:0;background-color:black">
</body>
</html>