adding different classes when coming from different pages

adding different classes when coming from different pages

Hello!

On load of my index page, I have a js running:

$(document).ready(function() {
            setTimeout(function(){
  $("body").addClass("item1")
 
I am leaving this page to page2 and returning to index.
Now I want to add:

 $("body").addClass("item2")
 
 If I come from page3 I want item3 to add.
 
 How can I achieve this?