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 1

    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);//ВозвращаСмся ΠΊ Π½Π°Ρ‡Π°Π»Ρƒ });