简体   繁体   中英

Closing the keyboard in Safari 15 on iPhone raises the window.blur event

Closing the keyboard in Safari 15 on an iPhone triggers the window.blur event. The problem is that the application must also listen for the window.blur event to send information that the user has minimized the application and closing the keyboard causes a false positive. Is it possible to somehow separate these cases?

You can use combination of VisibilityChange and BeforeUnload events to trigger when user minimises or navigates away from the website.

document.addEventListener("visibilitychange", (event) => { 
  // check visibilityState
  if(document.visibilityState === 'visible') {
    //.. do stuff
  } else { 
     // .. do something else
  }
});

document.addEventListener('beforeunload', () => {
 // Your logic goes here
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM