DIV CSS 佈局教程網

JavaScript 控制頁面跳轉的多種方式
編輯:關於JavaScript     

頁面跳轉可透過 location、history 或 top 等物件完成。最常見的是設定 window.location.href,也可用 history.back 返回上一頁。

若需要倒數跳轉,可搭配 setTimeout 顯示剩餘秒數,時間到後再導向目標網址。

window.location.href = 'login.jsp';

window.history.back(-1);

self.location = 'top.htm';

top.location = 'xx.jsp';
var seconds = 3;
var target = 'index.asp';

var timer = setInterval(function () {
  seconds--;
  document.getElementById('ShowDiv').innerHTML = '將在 ' + seconds + ' 秒後跳轉';
  if (seconds <= 0) {
    clearInterval(timer);
    window.location = target;
  }
}, 1000);
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved