I am using Javascript with the window.onload
and window.onbeforeunload
functions.
In the onbeforeunload
I want to run a code that removes an element from an existing list by iterating through the list via a method, but the method doesn't get executed.
When I use the same method in onload
, everything works fine.
I think the code doesn't get executed in the onbeforeunload
because the browser is already closed by then and that causes that the method doesn't get executed.
I think I need to do something Sychronous, do you guys have tips on how I can solve this?
// working
window.onload = function()
{
MethodA();
};
// not working
window.onbeforeunload = function()
{
MethodA();
};