頁面重定向是指使用者原本要前往 A 頁面,卻被導向 B 頁面。它常用於網域搬移、版本更新、依裝置或瀏覽器導向不同頁面等情境。
window.location = 'https://www.example.com/';
function Redirect() {
window.location = 'https://www.example.com/';
}
setTimeout(Redirect, 10000);
這種方式可先顯示一段提示訊息,再於 10 秒後跳轉。
const browsername = navigator.appName;
if (browsername === 'Netscape') {
window.location = 'https://www.example.com/ns.html';
} else if (browsername === 'Microsoft Internet Explorer') {
window.location = 'https://www.example.com/ie.html';
} else {
window.location = 'https://www.example.com/other.html';
}
不建議用重定向誤導搜尋引擎或使用者。若網站搬移,應搭配適當的伺服器端轉址與 SEO 規劃。