Hello guys, I work on website on webflow and had logout button in navbar which worked fine. addEvent listener function in custom code on classname .logout works fine as well. Problems started when i moved .logout button from navbar to dropdown. Logout only works once. If i navigate through pages it stops working. And I cant event alert or console something in local Embed code on .logout button click if I changed page after visiting website. Website is not mine so I cant edit custom code but I dont think problem is there. Does someone know what can cause this?
Wrap your .logout
event binding in a function & attach it to Webflow’s Webflow.push(function(){ ... })
, or re-bind it on every page change using the window.Webflow
ready events.
Example
function bindLogout()
{
const logoutBtn = document.querySelector(‘.logout’);
if (logoutBtn) {
logoutBtn.addEventListener(‘click’, function () {
// logout logic
}
);
}
}
document.addEventListener(‘DOMContentLoaded’, bindLogout);
document.addEventListener(‘readystatechange’, bindLogout);