Results 1 to 3 of 3

Thread: AJAX Pagination help

  1. #1
    Join Date
    Jan 2006
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question AJAX Pagination help

    http://www.dynamicdrive.com/dynamici...nate/index.htm

    Hello fellow programmers.

    I wanted to ask how is it possible to load an external html page which has the ajax pagination system but make it load on page 2 instead of 0...

    I saw this code which explains how to load another page when you are already in ajax pagination, but what about external pages?


    Selecting a page dynamically

    You can explicitly select a page within the paginated content to jump to anywhere on your page or inside your scripts by calling the method:

    Code:
    bookvarinstance.selectpage(page_number)
    Where "page_number" is an integer designating the desired page number to load (0=1st page, 1=2nd page etc). The following link selects the 3rd page of the paginated content instance with variable reference "comments":

    Code:
    <a href="javascript:comments.selectpage(2)">Jump to Page 3</a>
    Last edited by jscheuer1; 08-26-2012 at 12:52 AM. Reason: add link

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure what you're asking. But if you mean to ask how can I link to my AJAX Pagination page from another page and have it display a specific page, then put this code at the end of your page as shown, just before the closing </body> tag:

    Code:
    <script type="text/javascript">
    /* <![CDATA[ */
    (function(instance){
    	function getQval(n) {
    		if(typeof n !== 'string'){
    			return null;
    		}
    		var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
    		return (m = r.exec(m))? unescape(m[1]) : null;
    	}
    	var book = getQval('book');
    	if(book && (book = window[book]) && typeof book === 'object' && book.pages){
    		try{instance.refresh(book);} catch(e){}
    	}
    	var page = getQval('page');
    	if(page){
    		page = --page;
    		if(!isNaN(page)){
    			try{instance.selectpage(page);} catch(e){}
    		}
    	}
    })(mybookinstance);
    /* ]]> */
    </body>
    </html>
    Just make sure that the mybookinstance in the above is the name of the variable for your AJAX Pagination instance.

    Now, say your page with the AJAX Pagination script on it is called myajax.htm. You can have a link on another page to it like so:

    Code:
    <a href="myajax.htm?page=2">Open 2nd Page on myajax.htm</a>
    If you have other "books", you can select them in a similar fashion:

    Code:
    <a href="myajax.htm?page=11&book=bookcombo">Open 11th Page of bookcombo on myajax.htm</a>
    Be aware that unlike the on page links (javascript:mybookinstance.selectpage(1)) where the number is 0 based, with this method the 0 does nothing, 1 is the first page, 2 is the second, etc.
    Last edited by jscheuer1; 08-26-2012 at 02:52 AM. Reason: upgrade code to include books
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    feeleash (08-30-2012)

  4. #3
    Join Date
    Jan 2006
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Yes this was exactly what i was looking for!

    THANK YOU

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •