Keycloak redirection (from keycloak's account page to main application)

Hey there im working in an application tha uses keycloak service for authentication.
I want to add the functionality that i will explain after:
in the users profile account page provided by keycloak i want whenever i press a save or a cancel button the keycloak serveice to redirect me to the url that hosts my application.

until this monement i have written this script in javascript

const btns = document.getElementsByName("submitAction");
const redirect = () => {

setTimeout(() => {
    btnsArray = [...btns];
    btnsArray.forEach(btn => {
        btn.addEventListener("click", (evt) => {

but when i enable the preventDefault method on the event that fires up in a click i manage to redirect to the app page but for example when i change my password and press “save” the new password isnt changed…

on the other hand when i disable the preventDefault behaviour for my event the page instantly reloads (as it should ) and the result is that i cant reach the redirect() method so the redirection never happens…

any advice or workarounds?
thanks in advance!