How to use addEventListener to redirect to another html page on button click?

Advertisements

How to redirect to the next page using addEventListner?

Here, when I click the button it has to redirect to another HTML page
how to write the code for that.

HTML

<button>submit</button>

JS

let btn = document.querySelector('button')
btn.addEventListener('click', () => {
    
})

>Solution :

You can try this:

let btn = document.querySelector('button')
btn.addEventListener('click', () => {
    window.location.replace('http://www.example.com');
})

Leave a ReplyCancel reply