JavaScript를 사용하여 다른 웹페이지로 리디렉션하려면 코드는 다음과 같습니다. -
예시
<!DOCTYPE html>
<html>
<head>
<h1>Redirect to a Webpage Example</h1>
<button class="redirectBtn">Redirect</button>
<h2>Click the above button to Redirect to another Webpage</h2>
<script>
document .querySelector(".redirectBtn") .addEventListener("click", redirectFunction);
function redirectFunction() {
location.href("https://tutorialspoint.com/");
}
</script>
</body>
</html> 출력
위의 코드는 다음 출력을 생성합니다 -

"리디렉션" 버튼을 클릭하면 새 사이트로 리디렉션됩니다 -
