Connecting Tech Pros Worldwide Forums | Help | Site Map

Detecting when the user has gone back a page

Oenone
Guest
 
Posts: n/a
#1: Dec 6 '05
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


BootNic
Guest
 
Posts: n/a
#2: Dec 7 '05

re: Detecting when the user has gone back a page


> "Oenone" <oenone@nowhere.com> wrote:[color=blue]
> news:0Vglf.18435$y36.2178@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,[/color]

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*

Closed Thread