Why Blur And Focus Doesn't Work On Safari?
I have simple button like that:
Solution 1:
On Safari, buttons may not be focused on click (and because they do not focus, they do not trigger blur)
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
You can focus the button using javascript though
<!DOCTYPE html><htmllang="en"><head><scripttype="text/javascript">functionclickFunc(event) {
console.log(event, 'click');
event.target.focus();// Add me
};
functionblurFunc(event) {
console.log(event, 'blur');
};
</script></head><body><buttonclass="emoji-button-container"onblur="blurFunc(event)"onclick="clickFunc(event)"></button></body></html>
Solution 2:
It seems Safari doesn't focus button element on click. So, according to definition, onblur attribute fires the moment that the element loses focus. Element is not focused => onblur doesn't fire.
One of the solution could be manually apply button.focus()
after click.
Another one is to attach click
event on document
as here
Post a Comment for "Why Blur And Focus Doesn't Work On Safari?"