I have a website that reads like a book, first page to the next to the next to the previous page. Think of this as a forward and back page flip in a book. Its not the previous page in the browser, its within the pages themselves. Like you are changing pages in a book
I am trying to dynamically assign the links for a previous and next page buttons. Currently the pages are located in an Object with pageNum and fileName as keys
I am trying to set the previous link based on the the page number of the of the current page link. See example and code below.
var toc = [
{"pageNum": "1", "fileName": "index.html"},
{"pageNum": "2", "fileName": "about.html"},
{"pageNum": "3", "fileName": "work.html"},
{"pageNum": "4", "fileName": "blog.html"},
{"pageNum": "5", "fileName": "contact.html"},
];
var url = window.location.pathname;
var currentPage = url.substring(url.lastIndexOf('/')+1);
var prevPageNum;
var prevPage;
//Based on currentPage, find object entry in toc and apply related pageNum
toc.filter(function(toc){
if(toc.fileName == currentPage) {
$('#currentPageNumber').append(toc.pageNum);
}
});
/******* Last and Next Page Assignment *******/
toc.filter(function(toc){
if(toc.fileName == currentPage) {
prevPageNum = toc.pageNum-1;
prevPage = toc.fileName;
$('#prevPage').append(prevPage);
//final code
//$('#prevPage').attr("href",prevPage);
}
});
<a href="#" id="prevPage">Previous Page</a>
<a href="#" id="nextPage">Next Page</a>
EXAMPLE:
currentPage is about.html prevPage needs to be index.html