I have some HTML files with numeric names in a folder called Project like this:
230512.html 230519.html 230530.html 230630.html 240120.html
I want to add a "Next Page Button" to each file. When I click the button, the hyperlink takes me to the next page in ascending order.
So if I'm in 230530.html
, clicking the next page button should take me to 230630.html
. p>
The file name is basically a date in the format YYMMDD.html. Dates may not be consecutive.
Any ideas how to create such a script?
P粉4550931232023-09-11 18:40:19
Here is some code:
// get current filename let currentFileName = location.pathname.split('/').pop(); // Get the list of all HTML files in the "Project" folder let fileNames = [ '230512.html', '230519.html', '230530.html', '230630.html', '240120.html' ]; // Find the index of the current file in the list let currentIndex = fileNames.indexOf(currentFileName); // Calculate the index of the next file let nextIndex = (currentIndex + 1) % fileNames.length; // Get the name of the next file let nextFileName = fileNames[nextIndex];
If you are on the last page, nextFileName will return to index 0.