Results 1 to 10 of 10

Thread: Looking for a command for "go to next page alphabetically".

  1. #1
    Join Date
    Feb 2016
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Looking for a command for "go to next page alphabetically".

    Looking for a Java or Html5 command that would "Check self" and then go to the next page alphabetically (or numerically).

    Example: html pages as follows -- 011.html, 012.html, 013.html, 021.html, 022.html, ... If user is on page 013.html clicks forward button, user would be taken to 021.html.

    I have spent hours searching the web and forums but have not found anything.
    Maybe this is not possible, but if you have any ideas I'd appreciate it.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You would have to build a function yourself.

    Increment characters http://stackoverflow.com/questions/1...rement-letters

    Increment numbers - look into the increment (++) operator. Something like;
    Code:
    var $i = 0;
    i++;
    // $i now equals 1
    If you post an example of what you're trying to achieve, and your JavaScript so far, maybe somebody can offer more help.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    The browser will have no information about what other pages are available on the server, so this will probably have to be a server side PHP page which is called from the current page with a parameter. The PHP can then search the server (or preferably extract the name from a pre-built list file) for the next page in the sequence. For speed and simplicity I would use a list, but YMMV. The disadvantage is that the list will have to be updated every time a new page is added. You could have a cron job running on the server regularly to update the list of pages to save the manual updating.

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Quote Originally Posted by styxlawyer View Post
    The browser will have no information about what other pages are available on the server, so this will probably have to be a server side PHP page which is called from the current page with a parameter..
    JavaScript has this option to grab the page from the URL;
    Code:
    var parts = window.location.pathname; 
    var part_array = parts.split( '/' );
    var last_part = part_array.pop();
    alert(last_part); // returns 'page.htm'
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    JavaScript has this option to grab the page from the URL;
    .
    .
    Indeed it has, but that only returns the name of the current page in the browser. Javascript code has no direct access to the server and cannot provide information about what other pages are available. Only server-side scripting is capable of that.

  6. #6
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    You could try this:
    On all pages:
    Code:
    <script src="alph.js"></script>
    where alph.js is this:
    Code:
    var pages = ["011.html", "012.html", "013.html", "021.html","022.html", "023.html"];
    
    function prev()
    {
    for (i = 0; i < pages.length; i++) {if(pages[i]==document.URL.substring(document.URL.lastIndexOf('/')+1, document.URL.length)&&pages[i-1]){window.location.href=pages[i-1]}}
    }
    
    function next()
    {
    for (i = 0; i < pages.length; i++) {if(pages[i]==document.URL.substring(document.URL.lastIndexOf('/')+1, document.URL.length)&&pages[i+1]){window.location.href=pages[i+1]} }
    }
    Then:
    011.html:
    Code:
    <head>
    <script src="alph.js"></script>
    </head>
    
    <body>
    <h3 style="text-align: center">011.html</h3>
    <span onclick="prev()">PREV</span>
    <span onclick="next()">NEXT</span>
    </body>
    012.html:
    Code:
    <head>
    <script src="alph.js"></script>
    </head>
    
    <body>
    <h3 style="text-align: center">012.html</h3>
    <span onclick="prev()">PREV</span>
    <span onclick="next()">NEXT</span>
    </body>
    ...And so on.
    Last edited by Beverleyh; 02-05-2016 at 05:26 PM. Reason: Repetitive code/examples reduced.

  7. #7
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    That would be great except that every time a new page is added to the server or an old page deleted then "alph.js" would also need to be updated. Also, there is a problem when the page is 011.html or 023.html as the PREV and NEXT respectively buttons would produce out of array errors.

  8. #8
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    On 011.html we could just make the PREV-button invisible. Similar solution for 023.html.
    But yes, you're right about alph.js. I wouldn't know of another method to tell what pages are on the server.

  9. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Quote Originally Posted by styxlawyer View Post
    Indeed it has, but that only returns the name of the current page in the browser. Javascript code has no direct access to the server and cannot provide information about what other pages are available. Only server-side scripting is capable of that.
    Yes, I'm aware of that. However we don't know that the OP can use PHP as an option, and without further advice as to the nature of the project, I am only offering suggestions as to JavaScript's capabilities since that is the language asked for by the OP.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  10. #10
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Quote Originally Posted by styxlawyer View Post
    That would be great except that every time a new page is added to the server or an old page deleted then "alph.js" would also need to be updated. Also, there is a problem when the page is 011.html or 023.html as the PREV and NEXT respectively buttons would produce out of array errors.
    Going back to my first post - we really could do with more information from the OP. Otherwise, what have been offered so far are all valid suggestions in the unknown.

    It would probably be best to wait and see what the OP comes back with.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. Replies: 3
    Last Post: 10-13-2012, 08:01 PM
  2. Replies: 1
    Last Post: 02-28-2012, 02:21 AM
  3. playing backwards after a "load movie" command
    By niksan8787 in forum Flash
    Replies: 6
    Last Post: 01-14-2009, 08:50 PM
  4. How do I insert a target="_top" command
    By davidjovan in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 02-03-2006, 04:22 PM
  5. Script for "email a friend" and "print page"
    By pernes in forum JavaScript
    Replies: 0
    Last Post: 11-30-2005, 08:31 PM

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
  •