how to detect if user is at the last page of the history stack

E

|-|erc

when a user clicks back to get to my site, I want it to run a javascript
function.

can you detect when the FORWARD button is greyed out?

Herc
 
R

Randy Webb

|-|erc said the following on 8/21/2005 10:10 PM:
when a user clicks back to get to my site, I want it to run a javascript
function.

can you detect when the FORWARD button is greyed out?

No. It is none of your business where I came from or where I am going.

Besides, what difference does it make?
 
E

|-|erc

Randy Webb said:
|-|erc said the following on 8/21/2005 10:10 PM:

No. It is none of your business where I came from or where I am going.

Besides, what difference does it make?

windows.history.length will tell me how many sites are in your queue, so
you are wrong.

FORM --- submit ---> PAGE 2 [click Back to edit]

When you click back (from my own page again), the form data is still there
and you can edit it. But the javascript variables are reset so I need to
reinitialise them using data from the form.

Herc
 
J

John W. Kennedy

|-|erc said:
when a user clicks back to get to my site, I want it to run a javascript
function.

can you detect when the FORWARD button is greyed out?

Seeing that some browsers cache the DOM and others do not, I doubt any
general solution is even possible.
 
R

RobG

|-|erc said:
windows.history.length will tell me how many sites are in your queue, so
you are wrong.

The reply was in regard to determining if the forward button is enabled
or not. How does the history length tell you that?

Or are you saying that it *is* your business where Randy came from?
FORM --- submit ---> PAGE 2 [click Back to edit]

When you click back (from my own page again), the form data is still there
and you can edit it.

Are you using your back button or the browsers? If it's yours, then you
can attempt to do what you like by posting data to the server but if
it's the browser back button, then some browsers retain the values and
others don't.
But the javascript variables are reset so I need to
reinitialise them using data from the form.

Then (attempt) to do so onload and expect to fail some of the time.
 
E

|-|erc

John W. Kennedy said:
Seeing that some browsers cache the DOM and others do not, I doubt any
general solution is even possible.

so there's nothing like windows.history.length
but it tells you how far through the history you are?

say I wanted to make my own fast forward and fast back buttons.
go +10 or go -10 pages, but when you're near the ends, it changes to +2
or -2 pages.

That's impossible because you have no idea where in the history stack you
are??

Herc
 
E

|-|erc

RobG said:
The reply was in regard to determining if the forward button is enabled
or not. How does the history length tell you that?

Or are you saying that it *is* your business where Randy came from?

I'm saying

"its none of you business where I came from or where I am going" is not
true,

because I can easily tell how many sites you've been to.
What I'm asking for is whether some of those are ahead of me in the history.

FORM --- submit ---> PAGE 2 [click Back to edit]

When you click back (from my own page again), the form data is still there
and you can edit it.

Are you using your back button or the browsers? If it's yours, then you
can attempt to do what you like by posting data to the server but if
it's the browser back button, then some browsers retain the values and
others don't.
But the javascript variables are reset so I need to
reinitialise them using data from the form.

Then (attempt) to do so onload and expect to fail some of the time.

I get the default form values when I tried that... not onload but directly
parsed, code not contained in a function body. Onload may make a
difference.... just a pain its in my header file.

Herc
 
R

RobG

|-|erc said:
I get the default form values when I tried that... not onload but directly
parsed, code not contained in a function body. Onload may make a
difference.... just a pain its in my header file.

Try the following:

<body onload="alert(document.formA.elementA.value);">
<form name="formA">
<input type="text" value="fred" name="elementA">
</form>
</body>

In both IE and Firefox the following behaviour is observed:

1. On initial load, get an alert with 'fred'.
2. Change the value to 'sue', click reload or ctrl+R, get 'sue'.
3. Navigate to another site, press browser 'back' button, get 'sue'.
4. Click in address bar, press enter, get 'fred'.

If you run the script after the form but before onload, you will get the
default values, not the 'current' ones. It seems that the browsers are
loading the page, then looking at the cache to replace form values, then
running onload.
 
E

|-|erc

RobG said:
Try the following:

<body onload="alert(document.formA.elementA.value);">
<form name="formA">
<input type="text" value="fred" name="elementA">
</form>
</body>

In both IE and Firefox the following behaviour is observed:

1. On initial load, get an alert with 'fred'.
2. Change the value to 'sue', click reload or ctrl+R, get 'sue'.
3. Navigate to another site, press browser 'back' button, get 'sue'.
4. Click in address bar, press enter, get 'fred'.

If you run the script after the form but before onload, you will get the
default values, not the 'current' ones. It seems that the browsers are
loading the page, then looking at the cache to replace form values, then
running onload.

Right, I thought that would be a longshot, its strange when the form has SUE
right in front of you and the alert is giving you FRED! I'll just use
onload like I should have.

Herc
 
R

RobG

|-|erc said:
so there's nothing like windows.history.length
but it tells you how far through the history you are?

it's 'window.history', there is no 's' on the end.
say I wanted to make my own fast forward and fast back buttons.
go +10 or go -10 pages, but when you're near the ends, it changes to +2
or -2 pages.

That's impossible because you have no idea where in the history stack you
are??

RTFM. Pay particular attention to the statement "There is no public
standard that applies to this object":

<URL:http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_history.asp>
 
R

Randy Webb

|-|erc said the following on 8/21/2005 10:31 PM:
Randy Webb said:
|-|erc said the following on 8/21/2005 10:10 PM:


No. It is none of your business where I came from or where I am going.

Besides, what difference does it make?


windows.history.length will tell me how many sites are in your queue, so
you are wrong.

FORM --- submit ---> PAGE 2 [click Back to edit]

When you click back (from my own page again), the form data is still there
and you can edit it. But the javascript variables are reset so I need to
reinitialise them using data from the form.

That does not tell you:

1) How many sites *before* your site.
2) How many sites *after* your site.
3) What and where I was.

What's in my history trail is none of your business.

But to solve your problem, onload of the page, check your variables and
your forms and act accordingly. Then, forget about my history trail
because it won't matter.
 
E

|-|erc

Randy Webb said:
|-|erc said the following on 8/21/2005 10:31 PM:
Randy Webb said:
|-|erc said the following on 8/21/2005 10:10 PM:

when a user clicks back to get to my site, I want it to run a javascript
function.

can you detect when the FORWARD button is greyed out?

No. It is none of your business where I came from or where I am going.

Besides, what difference does it make?


windows.history.length will tell me how many sites are in your queue, so
you are wrong.

FORM --- submit ---> PAGE 2 [click Back to edit]

When you click back (from my own page again), the form data is still there
and you can edit it. But the javascript variables are reset so I need to
reinitialise them using data from the form.

That does not tell you:

1) How many sites *before* your site.
2) How many sites *after* your site.
3) What and where I was.

What's in my history trail is none of your business.

It tells you "how many sites are in your history trail" so your deduction is
flawed.
I can put up a page "BEEN TO 250 SITES TODAY ALREADY.... TIRED OF SURFING
YET?"
or "JUST STARTING ON THE COMPUTER TODAY... BEEN TO A HALF DOZEN SITES?"

Herc
 
R

Randy Webb

|-|erc said the following on 8/22/2005 7:49 PM:
It tells you "how many sites are in your history trail" so your deduction is
flawed.

No, your interpretation of my deduction is flawed. It will NOT tell you
where you are in the stack, only that you are in the stack and among X
number of pages. The fact that you think that is any of your business
also shows the fallacy in your thinking process.

I can put up a page "BEEN TO 250 SITES TODAY ALREADY.... TIRED OF SURFING
YET?"

I bet that would go over well..... Even though it isn't true. The
appropriate statement would be more like "According to your history
trail, you have visited J number of sites since your cache/history were
last cleared"/
or "JUST STARTING ON THE COMPUTER TODAY... BEEN TO A HALF DOZEN SITES?"

"Just started since clearing your history....."

Try this test:

Open the browser. In your case, use IE since it gives the history.length.

Navigate 200 or so pages.
Clear the history trail.
Close the browser.
Reopen the browser.
Open your "infallibly stupid page" that tells how many sites you have
been on.

How many does it show?

And then, explain if you have access to my history trail, why you can't
tell me whether the back or forward buttons or greyed or not, because
you can't. Its none of your business.
 

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
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top