473,549 Members | 5,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automagic Previous / Next Links

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.htm l">Previous</a> | <a href="foo03.htm l">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?

Ian
--
http://sundry.ws
Mar 18 '06 #1
24 2824
Ian Rastall wrote on 18 mrt 2006 in comp.lang.javas cript:
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.htm l">Previous</a> | <a href="foo03.htm l">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?


Using serverside J(ava)script/ASP:

<%@ language="jscri pt"%>
<%
thisOne = request.serverv ariables('SCRIP T_NAME')
thisNumber = +thisOne.replac e(/.*?\//g,'').replace(/\D+/g,'')

nextNumber = ++thisnumber
if(nextNumber<0 ||nextNumber>99 )nextNumber=0
nextNumber = (nextNumber<10) ?'0'+nextNumber :nextNumber

//about the same for lastNumber

%>

<a href="foo<%=las tNumber%>.html" >Previous</a> |
<a href="foo<%=nex tNumber%>.html" >Next</a>

Not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 18 '06 #2
Evertjan. wrote:
Using serverside J(ava)script/ASP:


Hi Evertjan. I've never used server-side JS, and don't know if
AffordableHost uses it. (I'd have to ask.) Two questions:

1. Would it require me to change the extensions?
2. Can it be done client-side?

What I'm trying to do is make every page as close to the same as
possible. I'm working with over 2,500 files right now, and doing them
by hand.

I wonder if a preprocessor would work, but that's a question for
CIWAH, I imagine.

Ian
--
http://sundry.ws
Mar 18 '06 #3
Ian Rastall wrote:
Evertjan. wrote:
Using serverside J(ava)script/ASP:
1. Would it require me to change the extensions?
That depends on the host
2. Can it be done client-side?
Then it would break if client side scripting was unavailable or turned off
(this covers a significant number of users and all major search engine
indexers).
I wonder if a preprocessor would work,
Probably
but that's a question for CIWAH, I imagine.


You could write one in JavaScript :)

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Mar 18 '06 #4
David Dorward wrote:
Ian Rastall wrote:
2. Can it be done client-side?


Then it would break if client side scripting was unavailable or turned off
(this covers a significant number of users and all major search engine
indexers).


Okay, here's an idea. This is along the lines of graceful degradation.
If I coded the "Previous | Next" entirely in JS, including the HTML
bits, it would simply not be there if the user had JS turned off, and
they would just go back up to the top of the file and refer to the
table of contents. Not as handy, but still useable. The site wouldn't
break.

So *is* this something that can be done client-side? I've realized
that a pre-processor would be almost as much trouble, and the reason I
ask about JS is so I don't have to change the extensions. I have no
idea how I would redirect 2,500 pages from .html to .php or something,
unless there were a way to do it in .htaccess. Granted, most people
probably have only the front page bookmarked, but still....

Ian
--
http://sundry.ws
Mar 18 '06 #5
Ian Rastall wrote:
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.htm l">Previous</a> | <a href="foo03.htm l">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?

Ian

Look at top.location.hr ef (which will be something like
"http://host/root/whatever/foo03.html")

Parse out the number, put the new number into that string and put it
into top.location.hr ef.
Mar 18 '06 #6
TheBagbournes wrote:
Look at top.location.hr ef (which will be something like
"http://host/root/whatever/foo03.html")

Parse out the number, put the new number into that string and put it
into top.location.hr ef.


Thanks! I'm definitely not sleeping now. :-)

Ian
--
http://sundry.ws
Mar 18 '06 #7
TheBagbournes wrote:
Parse out the number, put the new number into that string and put it
into top.location.hr ef.


Okay, I'm making progress, but I'm a bit stuck. The bottom of the page
looks like:

<a href="#" onclick="previo us();">Previous </a> | <a href="#"
onclick="next() ;">Next</a></p>

and in the <script> section, for the first function, there's:

var addy = top.location.hr ef;
function previous() {
var result1 = addy.indexOf(". html");
var num1 = addy.substring( result1-3,result1);
if(isNaN(num1)) {
num1 = addy.substring( result1-2,result1);
}
num1--;
}

I know it's a mess. The problem is, it's a string up until it gets
decremented, at which time it becomes a number, and loses the leading
0. This won't always be a problem, but it will whenever there's a
leading zero. I also have no idea how to put the number back into the
string. Am I going about this the wrong way?

Ian
--
http://sundry.ws
Mar 18 '06 #8
Ian Rastall wrote on 18 mrt 2006 in comp.lang.javas cript:
Evertjan. wrote:
Using serverside J(ava)script/ASP:
Hi Evertjan. I've never used server-side JS, and don't know if
AffordableHost uses it. (I'd have to ask.) Two questions:

1. Would it require me to change the extensions?


You would need a server with ASP. The extensins are usually .asp but could
be set to anything.
2. Can it be done client-side?
Sure, but not as nice and not as usefull.

[php would be just as good as ASP, but that is not j(ava)script]
What I'm trying to do is make every page as close to the same as
possible. I'm working with over 2,500 files right now, and doing them
by hand.
2,500 files without serverside programming does not sound very usable.

With serverside ASP and includes, you write only one include file and
include the file in all 2,500.
I wonder if a preprocessor would work, but that's a question for
CIWAH, I imagine.


Don't know anythng about that.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 18 '06 #9
Ian Rastall wrote on 18 mrt 2006 in comp.lang.javas cript:
TheBagbournes wrote:
Parse out the number, put the new number into that string and put it
into top.location.hr ef.


Okay, I'm making progress, but I'm a bit stuck. The bottom of the page
looks like:

<a href="#" onclick="previo us();">Previous </a> | <a href="#"
onclick="next() ;">Next</a></p>

and in the <script> section, for the first function, there's:

var addy = top.location.hr ef;
function previous() {
var result1 = addy.indexOf(". html");
var num1 = addy.substring( result1-3,result1);
if(isNaN(num1)) {
num1 = addy.substring( result1-2,result1);
}
num1--;
}

I know it's a mess. The problem is, it's a string up until it gets
decremented, at which time it becomes a number, and loses the leading
0. This won't always be a problem, but it will whenever there's a
leading zero. I also have no idea how to put the number back into the
string. Am I going about this the wrong way?


Yes you are.

Look at my earlier serverside code and use the same clientside:

=============== =============== ==

var thisNumber = top.location.hr ef;
thisNumber = +thisOne.replac e(/.*?\//g,'').replace(/\D+/g,'')

var lastNumber = thisnumber-1
if (lastNumber <0) lastNumber = 0
lastNumber = (lastNumber <10) ? '0'+lastNumber : lastNumber

document.write( '<a href="foo'+last Number +'.html">Last</a> |')

var nextNumber = thisnumber+1
if(nextNumber<0 ||nextNumber>99 )nextNumber=0
nextNumber = (nextNumber<10) ?'0'+nextNumber :nextNumber

document.write( '<a href="foo'+next Number+'.html"> Next</a>')

=============== =============== ===

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
10951
by: george | last post by:
Can anyone help? I query a database and return a result on the column "reference". There might be 7 listings. Each row is displayed in a table, with links through to a detail page. I am working on having a "previous" record and a "next" record link on the detail page. This code below works, for the "next" record, by searching the values...
9
1922
by: Leroy | last post by:
I really need some help with showing pages of results from queries in say like groups of 20 with next and previous buttons or links. I'm having a lot of trouble figuring out the logic of such a script. I know someone has written this script before. Please help.
3
3042
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I wanted to build in NEXT and PREVIOUS buttons, so that you only get 5 or 10 or 20 (I haven't made up my mind yet) thumbnails at a time. I use a SQL...
1
1951
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for the first page): display the section name, the current file and a few archive files. If there is more than a page full (for each additional page):...
4
3587
by: msnews | last post by:
Hi All, My client has following request. I am not sure how to do it. Dynamically from database, we are getting set of images names. Now we want to display them with next and previous buttons. I am able to pull all the information from database and put it in javascript array. Now using two functions for next and previous button, I am able...
2
3383
by: LizzyFin | last post by:
Looking for a little assistance in understanding what I am missing! Using PHP/MySql to allow users to browse through items in a gallery. Clicking 'next' and 'previous' links works fine using the item ID number to sequentially see all items. Trouble arises when category and ID variables are passed. I'm thoroughly confused on how to let the...
1
2407
by: Reb | last post by:
Hi all, I have not successfully found a Javascript sample for getting next and previous links from a file... I figured that someone must have solved this problem already! ... here is what I'm trying to do. I have a multi-framed file, with navigation in a top bar. Within each content directory, I have a file called nav.txt that lists the...
3
2286
by: karen987 | last post by:
Can someone please explain what code i need to add to keep a set of links at the bottom of a pop up window? I need it in a page where people post comments. It is a pop up window, of about 500x400 where peoople post comments, and can read the previous and next ones. I have tried aligning it to the bottom of the window, in a table using the...
1
2350
by: greatjuli | last post by:
Hi all, please I am quite new to PHP/ MySQL. I have got a table "members" and the DB name is "jutland". I have got columns - id, name, surname & email. I want to display 100 records with 5 rows per page using PHP going back and forth with previous(previous 5 rows) and next (next 5 rows) links. I have the knowledge of the LIMIT x, y condition but...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.