I need to refresh the webpage refresh every time when a user resume at the page. actually when user open my website all data retrived and shown to user. when user go outside the browser or switch tabs data remain same so when user come back to my tab or reopen browser i want to reload or refresh the page . so user get updated data every time.
i tried all methods
2
Answers
maybe you want to check out about websocket for showing realtime data for the ui. But since your asking how to refresh the page when user come back to the tab this maybe helps using visibilitychange events
heres an example:
the event will trigger when user leaves and enter the page so use if condition to execute your own code if you want.
You can use the
document.hasFocus()
method to detect if the user is currently viewing the webpage. To continuously check for changes in the user’s focus state, you can use thesetInterval()
method.Here’s the code:
I hope this is helpful to you