• Home
  • About
    • PI photo

      PI

      Beginner's Blog

    • Learn More
    • Github
  • Posts
    • All Posts
    • All Tags
    • All Categories
  • Projects

[JS] JS로 웹페이지 리다이렉트하는 법

📆 Created: 2024.12.26 Thu

Reading time ~1 minute

Page Redirect

JS를 이용해 다른 웹페이지로 리다이렉트하는 방법이다.
보통 location.href나 location.replace를 사용한다.

// Stimulate a Mouse Click 1
location.href = "example.com"; // 뒤로 가기 가능

// Stimulate a Mouse Click 2
location.assign("example.com"); // 뒤로 가기 가능

// Stimulate an HTTP Redirect
location.replace("example.com"); // 뒤로 가기 불가능

replace는 웹페이지 기록에서 현재 문서의 URL을 지우기 때문에 이전 페이지로 뒤로가기가 불가능하다.

참고

  • How TO - Redirect to Another Webpage
  • How to Redirect to Another Webpage using JavaScript?
  • JavaScript Redirect: How to Redirect to a New URL


TILWEBJS Share Tweet +1
/#disqus_thread