Gallery of photos on the site is made on css using anchors # img1 # img2, etc. The problem is that after viewing the photos, if you click back, then the last viewed photo (site.ru/page2/#img1) naturally pops up, and I would like to go to the previous page. Is it possible to do this?
1 answer
You can, but without clicking on the back (because DOM does not track events associated with clicking on this button), you will have to create your own return button. So what is next:
var clicker = 0;//Π‘ΠΏΠ΅Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½Π°Ρ. ΠΡΡΠ»Π΅ΠΆΠΈΠ²Π°Π΅Ρ ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ°Π· ΠΊΠ»ΠΈΠΊΠ½ΡΠ»ΠΈ. var links = document.getElementsByClassName("toLink");//ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ Π½Π°ΡΠΈ ΡΠΊΠΎΡΡ for(var i=0; i<links.length;i++){ links[i].onclick = function(){ clicker--;//Π‘ΡΠΈΡΠ°Π΅ΠΌ ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ°Π· ΠΊΠ»ΠΈΠΊΠ½ΡΠ»ΠΈ }; } var back = document.getElementById("back"); back.onclick(function(){ history.go(clicker);//ΠΠΎΠ·Π²ΡΠ°ΡΠ°Π΅ΠΌΡΡ ΠΊ Π½Π°ΡΠ°Π»Ρ });
|