Distinguish between page refreshes and closing event

Onbeforeunload refresh the page before execution and then execute onunload

Onunload executed only when the page is closed

Performed only when the page loads onload

Distinguished: onbeforeunload setting flag in onunload is determined whether the flag is present

window.onbeforeunload = _ =>{ this.refresh = true }

window.onunload = _ =>{ 判断this.refresh }

Guess you like

Origin www.cnblogs.com/lskzj/p/12173028.html