Front-end partners can learnMall source code acquisition github.crmeb.net/u/hang

In the process of H5 calling wechat payment, there must be a single page that does not refresh when returning to the order page. Therefore, I wonder if I can monitor the change of visibilitychange and call the method when returning to the page after switching to wechat

visibilitychange

When the contents of its tabs become visible or hidden, the VisibilityChange event is triggered on the document

document.addEventListener('visibilitychange', (e) => { console.log(document.visibilityState); Let state = document.visibilityState if (state == 'hidden') {console.log(' user left '); } if (state == 'visible') {// call interface, get order status}});Copy the code

Note that THE following is not compatible with IE10

Finally, I recommend a mall source Git address to you front-end partners, we can learn from each other

City base version of the source code