HTML: How to go to next page in ascending order?
P粉256487077
P粉256487077 2023-09-10 21:41:36
0
1
668

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.

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粉256487077
P粉256487077

reply all(1)
P粉455093123

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template