0

I have a Django project where I show a list of post titles in a forumhome page. Here is a typical action of a user.

  1. user clicks title of post A.
  2. user was directed to post A detail page
  3. user clicks browser back button, and go back to forumhome page with a list of posts.
  4. (!important) I want to show the user that certain posts were already read in the forumhome page.
  5. user repeat (1-4)

Currently, I was able to do the above by forcing browser to refresh the page when back button is clicked:

  • 1) track post view
  • 2) in forumhome page, check if a specific post was viewed by the user
  • 3) (!important) when the user clicks browser back button, I force the browser to refresh the page. I use Leonid Vasilev's answer from this post, copy-pasted below:
window.addEventListener( "pageshow", function ( event ) {
  var historyTraversal = event.persisted || 
                         ( typeof window.performance != "undefined" && 
                              window.performance.navigation.type === 2 );
  if ( historyTraversal ) {
    // Handle page restore.
    window.location.reload();
  }
});

What I want is rather than refreshing the whole page, only change the specific post(or posts) link to show that the post has been read by the user (like what gmail does on desktop or mobile-web). I know how to use ajax to like-unlike/bookmark posts, but I cannot find a way to do this. Any help? Thanks!

ha-neul
  • 3,058
  • 9
  • 24
  • 2
    Use react or some other SPA framework. If you want to write your own instead, you can use History API with fetch/ajax. – George Dec 30 '19 at 20:32
  • @George, thank you for your quick reply. at this moment, SPA is not my option. Could you point to me some tutorials or so questions that using History API/fetch/ajax to solve this type of problems? – ha-neul Dec 30 '19 at 21:39

0 Answers0