网页跳转实现的多种方式

时间:2022-05-22 17:23:21

1.PHP后台代码实现

function redirect($url) {
header('Location: ' . $url);
}

2.通过HTML代码实现

<head>
<meta http-equiv="refresh" content="5;url=hello.html">
</head>

3.通过js实现

/**
* 跳转
* @param {Object} url
* @param {Object} time
*/

function hrefTo(url, time) {
if (time == 0) {
window.location.href = url;
} else {
setTimeout("hrefTo('" + url + "',0)", time);
}
}