Dev0ps's avatar

Update if user read the post

I guys, I wanna make a code that will work only if other user can view/read the post for 10 seconds ( without click to open the post )

Once a user view a post for 10sec or stop scroll up/down ( focus to a specific post) then ajax function calls automatically

Anyone here knows how to make this sort of code?

0 likes
3 replies
vmitchell85's avatar

To recap your question:

You're looking to monitor where a user is on a page and if the user is on a specific place on the page for more than 10 seconds you want to make an ajax call to store some data regarding that post/spot on the page?

I think a combination of the HTML Intersection Observer API and a setTimeout would work for this.

HTML Intersection Observer API details can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

However this is an new/upcoming feature in browsers so the support isn't great. There does seem to be a polyfill though: https://github.com/w3c/IntersectionObserver/tree/master/polyfill

2 likes

Please or to participate in this conversation.