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

Detecting when the user has gone back a page

P: n/a
We have a little piece of JavaScript in one of our client's application
which automatically sets the input focus to the first control on the HTML
form.

This works very nicely, except for in one circumstance. If the user is
partway through entering data into the form, clicks a hyperlink to go to
another page, and then clicks the Back button to return to the edit page,
the focus is again reset to the first field on the page. Under this
circumstance I would like the focus to be left wherever the user has
previously put it.

Simply put, I want to only set the focus if the user hasn't already set it
during a previous access to this page.

I can do this in IE by querying the document.activeElement.tagName property.
If this returns BODY, then I know that the focus is in its default state and
can set it appropriately. But Firefox doesn't appear to support the
document.activeElement property, so I can't use this mechanism here.

Can anyone suggest a way to do this that will work in Firefox? The ideas I
have which may provide a solution are:

- see if the focus is set to the default location on the page (whatever that
is) -- how would I do this? I'm not sure how to determine what currently has
the focus in Firefox.

- see if there are pages in the history buffer ahead of the current page
(i.e., that would be reached by clicking the Forward button in the
browser) -- how would I do this?

If anyone could answer either of those questions, or suggest another way I
may be able to achieve my goal, I'd be very grateful.

Thanks in advance,

--

(O)enone
Dec 6 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> "Oenone" <oe****@nowhere.com> wrote:
news:0V******************@newsfe1-win.ntli.net....

We have a little piece of JavaScript in one of our client's
application which automatically sets the input focus to the first
control on the HTML form.

This works very nicely, except for in one circumstance. If the user
is partway through entering data into the form, clicks a hyperlink
to go to another page, and then clicks the Back button to return to
the edit page, the focus is again reset to the first field on the
page. Under this circumstance I would like the focus to be left
wherever the user has previously put it.

Simply put, I want to only set the focus if the user hasn't already
set it during a previous access to this page.

I can do this in IE by querying the document.activeElement.tagName
property. If this returns BODY, then I know that the focus is in
its default state and can set it appropriately. But Firefox doesn't
appear to support the document.activeElement property, so I can't
use this mechanism here.

Can anyone suggest a way to do this that will work in Firefox? The
ideas I have which may provide a solution are:

- see if the focus is set to the default location on the page
(whatever that is) -- how would I do this? I'm not sure how to
determine what currently has the focus in Firefox.

- see if there are pages in the history buffer ahead of the current
page (i.e., that would be reached by clicking the Forward button in
the browser) -- how would I do this?

If anyone could answer either of those questions, or suggest
another way I may be able to achieve my goal, I'd be very grateful.

Thanks in advance,


Use a hidden input to keep track of the elements onfocus.
<input id="tracker" type="hidden" disabled="true">

In each one of your form elements use the onfocus and set tracker value to the id
<input type="text" id="t1" name="address" onfocus="/* set tracker value to this id */">

Your onload can check to see if the hidden tracker element has a value, if it does you can set
focus to that id, if it does not you can set focus to an element of your choice.

--
BootNic Wednesday, December 07, 2005 1:56 AM

A priest, a minister and a rabbi walk into a bar. The bartender says...What is this, a joke?
*Unknown*

Dec 7 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.