var prevBtn = document.getElementById("prev");
var nextBtn = document.getElementById("next");
var i = 0;
var getPathname = window.location.pathname;
var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
function minus(){
i--;
if ( i === -1){
i = 0;
}
// // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
// // window.location.href = repetitivePath + i + ".html";
window.location.replace(repetitivePath + i + '.html');
console.log(i);
// // console.log(repetitivePath);
}
function plus(){
i++;
if ( i === 3){
i = 2;
}
// // var repetitivePath = getPathname.substring(0, getPathname.lastIndexOf("/") + 1);
// // window.location.href = repetitivePath + i + ".html";
window.location.replace(repetitivePath + i + '.html');
console.log(i);
// // console.log(repetitivePath);
}
prevBtn.addEventListener("click", function(){
minus();
})
nextBtn.addEventListener("click", function(){
plus()
})
The total file consists of index.html with this code and page files to be replaced: 1.html, 2.html, and 3.html.
When the prev button is pressed, -> i changes the address by adding the value of i and the string ".html" to the index value of the current address +1.
When the next button is pressed, -> i value becomes +1 and the rest is the same.
When the next button is pressed at first, it can be moved to 1.html, but it can't be moved to 2.html anymore.
How can we solve this problem? Please point it out!
url javascript
If you move to 1.html, the page will load anew, so the variable i value will be zero again.
If you are There is also a way to control the page by taking numeric values of /1.html, /2.html, /3.html.
© 2024 OneMinuteCode. All rights reserved.