I´m trying to add an EventListener
to my canvas when I lose focus in this canvas.
I have two canvases:
In the first canvas (at left), I draw a signature, and when change focus to the right canvas, I want the signature drawn on the first canvas to get saved in the server. I know how I can apply the logic to save in the server but I am unable to call the blur
event in the canvas.
To try this, I’m doing:
var canvas = document.getElementById("pizarra_cliente");
canvas.addEventListener("blur" , function() {
console.log("entro");
});
But if I put a debugger in the developer tools, I see the breakpoint is not being fired inside the blue
event. I tried with the onfocusout
as well but got the same problem.
Anybody can help me to create an event (focusOut
or blur
) to my canvas?
I´m using blur
because I read that this is an event that should be used in such use cases.
2
Answers
i get it with this logic:
I used
mouseout
event to get event and generate image with canvas data. My image it´s generated ok, and saved in my folder.If nothing works, you can use
window.addEventListener('click', e => {})
and check if the element is other than the canvas. You can use a flag to make it run only once, like: