LoginSignup
32
34

More than 5 years have passed since last update.

JavaScriptで指定したURLにページ遷移する方法

Posted at

例えば、http://example.comへ遷移したい場合、

location.href = 'http://example.com';

とするか、

location.assign('http://example.com');

とします。両者の違いですが、location.href property vs. location.assign() methodによると速度的な違いからlocation.href = '...'を使う方が良いとする人が多いようです。

また、上の2つの方法はページ遷移がブラウザの履歴に残るため、遷移後に戻るボタンで元のページヘ戻ることができますが、

location.replace('http://example.com');

とした場合、ブラウザの履歴に残らないため、戻るボタンで元のページヘ戻ることができません。

参考

32
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
34