想在頁面上放一顆刷新鈕,寫法其實不只一種。以下整理八種常見做法,可依情境挑用。
<input type=button value=刷新 onclick="history.go(0)">
<input type=button value=刷新 onclick="location.reload()">
<input type=button value=刷新 onclick="location=location">
<input type=button value=刷新 onclick="location.assign(location)">
<input type=button value=刷新 onclick="location.replace(location)">
<input type=button value=刷新 onclick="document.execCommand('Refresh')">
<input type=button value=刷新 onclick="window.navigate(location)">
<input type=button value=刷新 onclick="window.open('自身的檔名','_self')">
<input type=button value=刷新 onClick=document.all.WebBrowser.ExecWB(22,1)>
實務上最通用的是 location.reload(),語意清楚且相容性最好;history.go(0) 效果相同,但語意偏向瀏覽紀錄操作。最後幾種帶有明顯的 IE 專屬色彩,跨瀏覽器時要多留意。