Automagic Previous / Next Links

I

Ian Rastall

Lasse said:
If you know the algorithm for computing the link to the next/previous
page from the URL of the current one, sure:

Thanks, Lasse. I'll see if I can get that to work. I thought the
script I had written was working fine, but there were problems with
it, not least of which that when it runs into the first file it can't
go back any further ... though it tries. Thanks again.

Ian
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Sat, 18 Mar 2006 09:42:02 remote, seen in Ian
Rastall said:
I do a site where I have a previous and next link at the bottom of
every page. It looks like:

<p><a href="foo01.html">Previous</a> | <a href="foo03.html">Next</a></p>

Seeing as they're always in sequential order, is there a way to
automagically go to the previous file or the next file using JS?

You say elsewhere that you are editing 2500 pages manually.

Assuming you have access to DOS, Windows, or UNIX, you should be able to
do many repeated edits with MiniTrue.

Number your pages from, say, 10000 or 1000000 and then you will never be
troubled by leading zeroes.

If you have access to DOS or Windows, then COLS, via
<URL:http://www.merlyn.demon.co.uk/programs/00index.htm>,
should be able to generate a batch file to rename them ...
and a MiniTrue command file to alter all the extant links.


Use script to write that paragraph, and then in the absence of script it
will not appear; be sure to have always a link to the index page.

The script on each page should just be like

<script type="text/javascript"> LastNext() </script>

with function LastNext() defined in an Include file as in
<URL:http://www.merlyn.demon.co.uk/js-nclds.htm>.


To get the current page number, try

var N = +location.href.match(/(\d+)\.html/)[1]

To construct a new name

vat S = "foo" + (N+1) + ".html"
 
I

Ian Rastall

Dr said:
To get the current page number, try

var N = +location.href.match(/(\d+)\.html/)[1]

To construct a new name

vat S = "foo" + (N+1) + ".html"

Thanks, John. I will hopefully have this problem solved soon, and this
group has been a big help. Hope you're well,

Ian
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sat, 18 Mar
2006 17:51:13 remote, seen in Randy Webb
Sidenote: One thing that has not been mentioned yet as a drawback to
client-side scripting is that it has no way of knowing the last page
unless you update the script every time you add a page.

That's no great problem, since the script should be in an include file.

It's easy enough, if desired (assuming DOS batch or UNIX or HLL [*]) to
process the master directory and update the include file. IIRC, an
include file can cause another include file to be included; and that
only need contain

var MaxPage = 1002500

which can readily enough be generated in Batch.


Alternatively, label the Next button "Try for the next page" ... <g>.


[*] In Win32+, that could be done with the aid of javascript executed by
CSCRIPT, or by in DOS/Win/UNIX by MiniTrue; example :

dir *.bat | mtr -c- -x+ -o "^\s*(\d+) file\(s\).*" = "\r\n\tvar MaxPage = \1\r\n\r\n"

-> var MaxPage = 25

which edits the
25 file(s) 10,599 bytes
line given by DOS dir.

Or, for not too many files,

dir *.bat | OVER | COLS & #9 ` 'var * 'MaxPage * '= * 1-10 .
-> var MaxPage = 25

or HUNT *.bat q0 | COLS &3 #9 ` 'var * 'MaxPage * '= * 31+7 .

HUNT, OVER, COLS, for DOS, via
<URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top