By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,587 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,587 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
--
I call3d this fugly and I'm proud www.supernerd.com.au/~gray77/kath1.jpg
Aug 22 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
|-|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?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 22 '05 #2

P: n/a
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|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.

Herc

Aug 22 '05 #3

P: n/a
|-|erc wrote:
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.

--
John W. Kennedy
"Never try to take over the international economy based on a radical
feminist agenda if you're not sure your leader isn't a transvestite."
-- David Misch: "She-Spies", "While You Were Out"
Aug 22 '05 #4

P: n/a
|-|erc wrote:
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|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.


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.

--
Rob
Aug 22 '05 #5

P: n/a
"John W. Kennedy" <jw*****@attglobal.net> wrote in
|-|erc wrote:
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.


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

Aug 22 '05 #6

P: n/a
"RobG" <rg***@iinet.net.au> wrote in
|-|erc wrote:
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|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 javascriptfunction.

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.


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

Aug 22 '05 #7

P: n/a
|-|erc wrote:
"RobG" <rg***@iinet.net.au> wrote in

[...]

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.


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.

--
Rob
Aug 22 '05 #8

P: n/a
"RobG" <rg***@iinet.net.au> wrote in ...
|-|erc wrote:
"RobG" <rg***@iinet.net.au> wrote in

[...]

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.


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

Aug 22 '05 #9

P: n/a
|-|erc wrote:
"John W. Kennedy" <jw*****@attglobal.net> wrote in
|-|erc wrote:
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.

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>
--
Rob
Aug 22 '05 #10

P: n/a
|-|erc said the following on 8/21/2005 10:31 PM:
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|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.

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 22 '05 #11

P: n/a
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|erc said the following on 8/21/2005 10:31 PM:
"Randy Webb" <Hi************@aol.com> wrote in ...
|-|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 javascriptfunction.

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

Aug 22 '05 #12

P: n/a
|-|erc said the following on 8/22/2005 7:49 PM:
"Randy Webb" <Hi************@aol.com> wrote in ...

<snip>

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.


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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 23 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.