search

Home  >  Q&A  >  body text

javascript - Can mobile h5 detect refreshing or leaving the page?

Can I monitor the page refresh or leave this page on the mobile h5 page?

过去多啦不再A梦过去多啦不再A梦2804 days ago640

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:36:58

    You can use onbeforeunload and onunload

    reply
    0
  • 迷茫

    迷茫2017-05-16 13:36:58

    You can use HTML5’s Page Visibility API

    document.visibilityState: Values ​​representing the following 4 possible states:
    hidden: the page is in the background tab or the browser is minimized
    visible: the page is in the foreground tab
    prerender: the page performs pre-rendering processing off the screen document. The value of hidden is true
    unloaded: The page is being unloaded from memory
    Visibilitychange event: This event is triggered when the document changes from visible to invisible or from invisible to visible.

    reply
    0
  • Cancelreply