Tell is this is back page in the history

P

pmelanso

Hello,
How can I tell if there is a page to go back to in the history or
not??? Same with forward??? say something like///

if (there is a page to go back to ) {
// DO something
}else {

}

and simularly

if(there is a page to go forward to ) {
//DO something else
}else {

}

Thanks,Pam
 
R

Randy Webb

(e-mail address removed) said the following on 11/7/2005 1:41 PM:
Hello,
How can I tell if there is a page to go back to in the history or
not??? Same with forward??? say something like///

You can't.
 
V

VK

Hello,
How can I tell if there is a page to go back to in the history or
not??? Same with forward??? say something like///

if (there is a page to go back to ) {
// DO something
}else {

}

and simularly

if(there is a page to go forward to ) {
//DO something else
}else {

}

// To go back:
history.go(-1);
// history.back() method is OK too, but
// it's sometimes blocked on some browsers
// for some misterious security reasons.

// To go forward:
history.go(1);
// history.forward() method is OK too, but
// it's sometimes blocked on some browsers
// for some misterious security reasons.

If no page to go back or forward, user will stay on the current page,
no error will happen, so don't worry.

history.length will give you some idea about how much did user navigate
before she came here. Only "some idea" because this counter has some
limitations too numerous to describe them here. But if you really want
to - then you can:

if (history.length) { // at least one page before mine
history.go(-1);
}
 
T

Thomas 'PointedEars' Lahn

VK said:
history.length will give you some idea about how much did user navigate
before she came here. Only "some idea" because this counter has some
limitations too numerous to describe them here. But if you really want
to - then you can:

if (history.length) { // at least one page before mine
history.go(-1);
}

history.length gives exactly no indication whether there is a previous (or
next) URI in the history or not. For example, it yields 50 in my (TBE
enhanced) Firefox no matter which site in the tab's history I am visiting.

I am not surprised by that:

<http://docs.sun.com/source/816-6408-10/history.htm#1193301>


PointedEars
 
R

Randy Webb

VK said the following on 11/7/2005 6:12 PM:
// To go back:
history.go(-1);
// history.back() method is OK too, but
// it's sometimes blocked on some browsers
// for some misterious security reasons.

Only if there is a page to go back to, and you have no reliable way to
determine that.
// To go forward:
history.go(1);
// history.forward() method is OK too, but
// it's sometimes blocked on some browsers
// for some misterious security reasons.

Only if there is a page to go forward to, and you have no reliable way
to determine that.
If no page to go back or forward, user will stay on the current page,
no error will happen, so don't worry.

But they will have a broken link which indicates incompetence on the
part of the programmer.
history.length will give you some idea about how much did user navigate
before she came here. Only "some idea" because this counter has some
limitations too numerous to describe them here. But if you really want
to - then you can:

No you can't, you just think you can.
if (history.length) { // at least one page before mine

No, it means there is a length to the history.

Open page1.html, navigate to page2.html, press the back button to go
back to page1.html. Check history.length. Then, read my response and
believe it.
 
S

Stephen Chalmers

Hello,
How can I tell if there is a page to go back to in the history or
not???

Even if there were a property like 'history.currentIndex' it would
represent the entire browsing history of the current window, not just
that of the pages visited on your site.
 
P

pmelanso

i would just like to know for the window.. i am developing a web
application (using asp .net/visual basic .net/javascript) right now and
have back/forward "buttons" (really just images linked to
history.back()) in a pop up window used for help and I want to display
a different "greyed" out image when there isn't a page to go
back/forward to.
 
P

pmelanso

i would just like to know for the window.. i am developing a web
application (using asp .net/visual basic .net/javascript) right now and
have back/forward "buttons" (really just images linked to
history.back()) in a pop up window used for help and I want to display
a different "greyed" out image when there isn't a page to go
back/forward to.
 
R

Randy Webb

(e-mail address removed) said the following on 11/7/2005 9:10 PM:
i would just like to know for the window.. i am developing a web
application (using asp .net/visual basic .net/javascript) right now and
have back/forward "buttons" (really just images linked to
history.back()) in a pop up window used for help and I want to display
a different "greyed" out image when there isn't a page to go
back/forward to.

Must not be much of an app if you haven't figured that out yet. Create
your own history trail and track. Either in a cookie, on the server, or
in the page itself.
 
D

David Wahler

i would just like to know for the window.. i am developing a web
application (using asp .net/visual basic .net/javascript) right now and
have back/forward "buttons" (really just images linked to
history.back()) in a pop up window used for help and I want to display
a different "greyed" out image when there isn't a page to go
back/forward to.

Just out of curiosity, is there any particular reason you think your
users need two sets of back/forward buttons?

-- David
 
V

VK

VK said the following on 11/7/2005 6:12 PM:
Randy Webb wrote:
No, it means there is a length to the history.

Open page1.html, navigate to page2.html, press the back button to go
back to page1.html. Check history.length. Then, read my response and
believe it.

I do believe you as deep as I do believe in The Array - that's the
highest swear you may expect from me :)

Sorry I was ambiguos in my post:
if (history.length) ...
check *may* tell you if browser has history.length property and if
there was *any* navigation during the current session. The latter check
may also fail easily if the previous page was the first in the session
and if you came on the current page via replace() method supported by
some browsers.
So history.length doesn't give you any idea where (by the index
position) are you now and its counter is not accurate in many
circumstances.

if (history.length) {history.go(-1);} is just additional check to avoid
some (but not all at all) situations.
 

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

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top