Why window.addEventListener('blur') and ('focus') event can be triggered at the same time? | XM Community
Question

Why window.addEventListener('blur') and ('focus') event can be triggered at the same time?

  • 19 June 2020
  • 0 replies
  • 191 views

Userlevel 1
Badge

I add Javascript window.addEventListener('blur') and window.addEventListener('focus') in each page to record the timestamp of blur event or focus event triggered by the respondent. Whenever the window is blurred, I appended a new timestamp of 'blur' . So if the page lost focus and got focus twice, I will have a sequence of the timestamp for losing focus and getting focus as:
1st losefocus 2020-04-17 23:14:54
1st getfocus 2020-04-17 23:15:13
2nd losefocus 2020-04-17 23:15:22
2nd getfocus 2020-04-17 23:15:28
But weirdly, sometimes I will get the same timestamp for 'lose focus' and 'get focus', or these two timestamps are super close (See an example below). I don't think that within 1 second, a respondent can at the same time first lose focus and then get focus back. Do you know why is this happening?
losefocus1 2020-04-17 14:14:02
getfocus1 2020-04-17 14:14:02
losefocus2 2020-04-17 14:14:02
getfocus2 2020-04-17 14:14:03
losefocus3 2020-04-17 14:14:03
getfocus3 2020-04-17 14:14:04

Even more weirdly, the timestamp of losing focus and getting focus back can be after the timestamp of clicking on the submission button (I recorded the timestamp when the respondent hits the submit button as well).
losefocus1 2020-04-17 23:14:54
getfocus1 2020-04-17 23:15:13
losefocus2 2020-04-17 23:15:22
getfocus2 2020-04-17 23:15:28
losefocus3 2020-04-17 23:18:21
getfocus3 2020-04-17 23:18:30
losefocus4 2020-04-17 23:20:35
getfocus4 2020-04-17 23:30:13
losefocus5 2020-04-17 23:30:14
getfocus5 2020-04-17 23:31:17
submit 2020-04-17 23:16:00

My code is attached below.
Screen Shot 2020-06-18 at 9.20.50 PM.png


0 replies

Be the first to reply!

Leave a Reply