Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4607298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:59+00:00 2026-05-22T00:40:59+00:00

i have this .js file for the pagination in html anybody can help me

  • 0

i have this .js file for the pagination in html anybody can help me what i have to change to show the different url for each page & user can save that url & can use it for future use to go on that specific page.

(.js file start from below)

function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;

this.showRecords = function(from, to) {        
    var rows = document.getElementById(tableName).rows;
    // i starts from 1 to skip table header row
    for (var i = 1; i < rows.length; i++) {
        if (i < from || i > to)  
            rows[i].style.display = 'none';
        else
            rows[i].style.display = '';
    }
}

this.showPage = function(pageNumber) {
    if (! this.inited) {
        alert("not inited");
        return;
    }

    var oldPageAnchor = document.getElementById('pg'+this.currentPage);
    oldPageAnchor.className = 'pg-normal';

    this.currentPage = pageNumber;
    var newPageAnchor = document.getElementById('pg'+this.currentPage);
    newPageAnchor.className = 'pg-selected';

    var from = (pageNumber - 1) * itemsPerPage + 1;
    var to = from + itemsPerPage - 1;
    this.showRecords(from, to);
}   

this.prev = function() {
    if (this.currentPage > 1)
        this.showPage(this.currentPage - 1);
}

this.next = function() {
    if (this.currentPage < this.pages) {
        this.showPage(this.currentPage + 1);
    }
}                        

this.init = function() {
    var rows = document.getElementById(tableName).rows;
    var records = (rows.length - 1); 
    this.pages = Math.ceil(records / itemsPerPage);
    this.inited = true;
}

this.showPageNav = function(pagerName, positionId) {
    if (! this.inited) {
        alert("not inited");
        return;
    }
    var element = document.getElementById(positionId);

    var pagerHtml = '<span onclick="' + pagerName + '.prev();" class="pg-normal"> &#171 Prev </span> | ';
    for (var page = 1; page <= this.pages; page++) 
        pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
    pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal"> Next &#187;</span>';            

    element.innerHTML = pagerHtml;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:41:00+00:00Added an answer on May 22, 2026 at 12:41 am

    in this.showPage() update the url hash with something like “pg=1”:

    location.hash = "#pg=" + pageNumber;
    

    That method will add an item to your page history. If you don’t want to add an item to your page history, use this:

    location.replace("#pg=" + pageNumber);
    

    Then, when the page is loaded, after you call pager.init(), you’ll want to call pager.showPage(). You can use this code to decide whether to load the first page or the page from the url::

    var page = /\bpg=(\d+)\b/.test(location.hash) ? parseInt(RegExp.$1) : 1;
    pager.showPage(page);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really hope someone can help with this problem. I have an ajax pagination
I have this html file where I want to overlay some text over another.
I have a view file like this : <html> <head> <meta name=layout content=main />
i have a situation where im apending html to load more posts(pagination), and each
I have this file: geoView.html.erb <meta name=viewport content=initial-scale=1.0, user-scalable=no /> <%= stylesheet_link_tag 'application' %>
I have this file: app/views/listings/list.html.erb in my rails project. Here are the contents of
I have this file file.txt which I want to split into many smaller ones.
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have this file which I need to read the first bytes to check
I have this class file call SMSHelper.cs First I just wanted to know is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.