location
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><a href="http://www.sdau.edu.cn"><span>5</span>秒钟跳转到首页</a><script>const a = document.querySelector('a')let num = 5let timerId = setInterval(function () {num--a.innerHTML = `<span>${num}</span>秒钟跳转到首页`if (num === 0) {clearInterval(timerId)location.href = 'http://www.sdau.edu.cn'}}, 1000)</script>
</body></html>
navigator
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script>(function () {const userAgent = navigator.userAgent// 验证是否为Android或iPhoneconst android = userAgent.match(/(Android);?[\s\/]+([\d.]+)?/)const iphone = userAgent.match(/(iPhone\sOS)\s([\d_]+)/)// 如果是Android或iPhone,则跳转至移动站点if (android || iphone) {location.href = 'http://m.itcast.cn'}})();</script>
</head><body></body></html>
history
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head><body><button>后退</button><button>前进</button><script>const back = document.querySelector('button:first-child')const forward = back.nextElementSibling//下一个兄弟back.addEventListener('click', function () {// history.back()history.go(-1)})forward.addEventListener('click', function () {// history.forward()history.go(1)})</script>
</body></html>