目次
指定したURLに移動
| location.href = URL; | 
- location.hrefにURLを指定すると、指定したURLに移動します。
- 遷移先のブラウザの戻るbuttonを押して遷移元に戻ることができます。
<input type="button" value="button1" onclick="clickBtn1()"/>
<script>
function clickBtn1(){
	location.href = "http://www.example.com";
}
</script>指定したURLに遷移します。
指定したURLに移動+戻るbutton不可
| location.replace(URL); | 
- location.replaceの引数にURLを指定すると、指定したURLに移動します。
- 遷移先のブラウザの戻るbuttonは、使用不可になり遷移元に戻れません。
<input type="button" value="button2" onclick="clickBtn2()"/>
<script>
function clickBtn2(){
	location.replace("http://www.example.com");
}
</script>指定したURLに遷移します。遷移先のブラウザの戻るbuttonは使用不可になります。
現在ページをリロードする
<input type="button" value="button1" onclick="clickBtn1()" />
<script>
  function clickBtn1() {
    location.reload();
  }
</script>
現ページをリロードします。
前のページに移動
| hisotry.back() | 
- hisotry.backは、表示していた前のページに移動します。
- ブラウザの戻るbuttonを押したときと同じ動きです。
- history.go(-1) と同じ意味です。
- history.go(0)またはhistory()は現在のページを再読み込みします。
移動元ページ test1.html
<p>テストページ</p>
<a href="test2.html">test2へ移動</a>
移動先ページ test2.html
<input type="button" value="button3" onclick="clickBtn3()"/>
<script>
function clickBtn3(){
	history.back();
}
</script>ボタンをクリックすると前のページ(test1.html)に移動します。
aタグのリンクで戻る場合
<a href="" onclick="window.history.back(); return false;">戻る</a>inputタグ内のonclickで戻る場合
<input type="button" onclick="window:history.back();" value="戻る" />次のページに移動
| hisotry.forward() | 
- hisotry.forwardは、表示していた次のページに移動します。
- ブラウザの次へbuttonを押したときと同じ動きです。
- history.go(1) と同じ意味です。
<input type="button" value="button4" onclick="clickBtn4()"/>
<script>
function clickBtn4(){
	history.forward();
}
</script>次のページに移動します。
関連の記事
JavaScript ウィンドウ/ダイアログを開くサンプル
JavaScript 一定間隔で処理を繰り返す (setInterval)
JavaScript 一定時間の経過後に処理を行う (setTimeout)
