Addeventlistener for User Profile Block

Hi,

I can find the addeventlistener for form and list block, however, how about user accounts block?

I am trying to have a redirection to specific link after pressing the update button, however, it is not working, just wonder if the eventlistener is not correct.

<script>
window.addEventListener('submit-form-user-accounts1', (e) => {
  console.log('form submit success', e.detail);
  const redirectUrl = `https://www.couponly.io/summary`;
  setTimeout(() => {
    window.location.href = redirectUrl;
  }, 2000);
});
</script>

Hope to have some advice on it.

Tks & Bgds

Eric

Hi @twmeric please, insert this custom code into Page Settings>Custom Code>Header field to redirect to the mentioned url once the Profile information is successfully updated on User Profile block

<script >

    function addClassNameListener(elemId) {
        var elem = document.getElementById(elemId);
        if (!elem) {
            return;
        }
        window.setInterval(function() {

            if (elem.classList.contains('sw-btn-success')) {
                const redirectUrl = `https://www.couponly.io/summary`;
                setTimeout(() => {
                    window.location.href = redirectUrl;
                }, 2000);
            }
        }, 1000);
    }

window.addEventListener("load", (event) => {
    addClassNameListener("sw-update-profile-btn");
});

</script>

@Maria, I tried this and was not able to get it to work. I have the profile block embeded on a non-default page. Is it possible that the elements would have different names?

Hi @mb12142329 you inserted it in the page of User Profile or where you have it embedded?

I actually tried both

@mb12142329 Looks like the code no longer works on the User Profile block since we moved it to React. I will share the updated code soon. Please, make sure to add it on the main page where you have your User Profile block and not in the page where it is embedded.

Hi @mb12142329 and @twmeric
Please, use this one on a new User Profile block and change url from https://www.couponly.io/summary to a respective one in const redirectUrl = https://www.couponly.io/summary` part

<script >
    function handleRedirect() {
        var elem = document.querySelectorAll('button[type=submit]')[0];
        if (!elem) {
            return;
        }
        window.setInterval(function() {

            if (elem.querySelector('.success-icon')) {
                const redirectUrl = `https://www.couponly.io/summary`;
               
                setTimeout(() => {
                    window.location.href = redirectUrl;
                }, 2000);
            }
        }, 500);
    }

window.addEventListener("load", (event) => {
    handleRedirect();
});
</script>
1 Like