JS瀏覽器對象-History對象

來源:互聯網
上載者:User

標籤:

 

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>uvi</title>     <link rel="stylesheet" href="style.css" type="text/css"></head><body>   <button id="btn" onclick="goceshi()">按鈕</buton>   <script>      function goceshi(){          history.back();      }   </script>   </body></html>

 

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>uvi</title>     <link rel="stylesheet" href="style.css" type="text/css"></head><body>   <a href="index9.html">跳轉到index.html頁面</a>   <button id="btn" onclick="">按鈕</button>   <script>      function goindex9(){          history.forward();      }   </script></body></html>

 

下面的例子示範:點擊ceshi.html的連結跳轉到index10.html登陸頁面,然後輸入正確的使用者名稱("hello")後又返回到之前的頁面ceshi.html

                       即利用了history.go(-1)

ceshi.html

 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>uvi</title> 6      <link rel="stylesheet" href="style.css" type="text/css"> 7 </head> 8 <body> 9    <a href="index10.html">跳轉到index.html頁面</a>10    11 </body>12 </html>

 

index10.html

 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>uvi</title> 6      <link rel="stylesheet" href="style.css" type="text/css"> 7 </head> 8 <body> 9    <form>10    <input type="text" id="username">11    </form>12    <button id="btn" onclick="safe()">按鈕</button>13    <script>14       function safe(){15           var name = document.getElementById("username").value;16           alert(username);17           if(name=="hello"){18               history.go(-1);//回到之前的介面19           }else{20               alert("輸入錯誤");21           }22       }23    </script>24    25 </body>26 </html>

 

JS瀏覽器對象-History對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.