瀏覽器中的前進和後退程式碼window.history.go(-1),history.back()
阿新 • • 發佈:2019-02-20
history.go(),
history.back(),//後退一頁
history.forward()//前進一頁
window.history.go(-1);//後退一頁
window.history.go(-n);//後退n頁
window.history.go(1);//前進一頁
window.history.go(n);//前進n頁
window.history.go(0);//重新整理頁面
上面的後退,我在本地試過,貌似都不會清空上一頁表單內的資料,
window.location = document.referrer //後退一頁並且重新整理頁面(頁面表單內資料不儲存)
//重新整理當前頁面
function onclik2(){
history.go(0);
location.reload();
location=location;
location.assign(location);
location.replace(location);//這個函式挺好用的,,就相當於跳轉頁面的作用,把當前頁面替換成括號中網頁
}
<input type ="button" onclick="location.reload();" value="重新整理"/>
<input type ="button" onclick="window.history.go(-1)" value="後退"/>
<input type ="button" onclick="history.forward()" value="前進"/>
注:
如果history.go()和history.back()都沒有起作用,
用下來應該是可以起作用,因為我之前就是用go和back都沒有用,然後就找到了下面的這種方法,然後就可以了
<input type ="button" onclick="javascript:window.history.back();return false;" value="後退"/>