Javascript的History對象

來源:互聯網
上載者:User

一、瞭解history對象

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 5 <title>無標題文檔</title> 6 <script language="javascript"> 7 //History:對象用於記錄操作瀏覽器的訪問曆史,History對象是Window對象的一部分,可以通過Window.History屬性進行訪問 8 //提示:History 對象的有效作用範圍都是指當前視窗。 9 //------------------history對象的屬性--------------------10 //只有唯一的屬性 length    用於得到瀏覽器訪問記錄中的 URL 數量11 document.write(history.length);12 //注意:該例子輸出的結果取決於當前頁面的瀏覽記錄,如果是新視窗開啟該例子,IE 瀏覽器會輸出 0(即從 0 開始計算),而 Firefox、Chrome 等瀏覽器則會輸出 1。13 14 //------------------history對象的方法--------------------15    //No1、history.back():返回前一個瀏覽頁面(如果存在)16    //No2、history.forward():前往下一個瀏覽頁面(如果存在)17    //No3、history.go():前往 history 列表中的某個指定頁面(如果存在)18     /*文法如下:19              history.go(number|url)20              參數說明:number:要訪問的頁面相對當前頁面的位置,負整數表示往後返回,正整數表示往前進21              url:要訪問的 URL,或 URL 的子串22     */23 </script>24 25 </head>26 27 <body>28 <a href="window.history.back()">返回上一頁</a><!--或者:history(-1)-->29 <a href="window.history.forward()">前往下一頁</a><!--或者:history(1)-->30 <a href="window.history.go(2)">BeginMan</a>31 </body>32 </html>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.