Как сделать редирект на главный страницу, тобишь на главный html файл?

Вот код html с кнопкой:

    <!DOCTYPE HTML>
<html>

<head>

    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"/>
    
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    
    <meta name="HandheldFriendly" content="true"/>

    <title>Регистрация</title>

    <script src='./js/script.js'></script>

    <link rel="stylesheet" href="./css/style.css" />
    
</head>

<body>
    
    <form>

        <div class='group'>
            <center><button id="addButton">Registration</button></center>
        </div>
        
    </form>
            
</body>

</html>

Вот код js:

(function (window, document) {
    window.onload = init;
    function init() {
        var button = document.getElementById("addButton");
        button.onclick = handleButtonClick; 
}
    function handleButtonClick() {
        location = "main.html"; 
}
})(window, document);

Файл index.html который содержит форму регистрации и кнопку, после нажатия на кнопку должен редиректить на файл main.html, который так же расположен в папке с index.html, но js скрипт почему то не работает. Если заменить location = 'main.html'; на alert('123'); то после нажатия на кнопку почему то все работает, помогите исправить данную проблему, буду благодарен, заранее спасибо


Ответы (4 шт):

Автор решения: Serge Koflik

Попробуйте заменить location = "main.html"; на location.href = "main.html";

→ Ссылка
Автор решения: Алекс Данилин
window.location.assign('/main.html')

— так попробуй

→ Ссылка
Автор решения: Вадим Александру

Нужно отменить дефолтный обработчик формы.

(function (window, document) {
    window.onload = init;
    function init() {
      var button = document.getElementById("addButton");
      button.onclick = handleButtonClick;
    }
    function handleButtonClick(e) {
      e.preventDefault()
      location.href = 'main.html'
    }
  })(window, document);
→ Ссылка
Автор решения: Igor

По нажатию на кнопку происходит отправка формы и перезагрузка страницы. Сделайте как в ответе @ВадимАлександру или:

<button type="button" id="addButton">Registration</button>
        ^^^^^^^^^^^^^
→ Ссылка