473,796 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting when the user has gone back a page

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.active Element.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.active Element 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
1 2826
> "Oenone" <oe****@nowhere .com> wrote:
news:0V******** **********@news fe1-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.active Element.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.active Element 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3956
by: Astra | last post by:
Hi All I've noticed on quite a few ASP sites that when they have a 'MyAccount' section they transfer the site to https and then when you have logged into your account successfully and gone back to the majority of the site you move back to http whilst still being logged in. I've used the Session var method before to check if a user can have access to pages, but how on earth can I keep a handle on this when I flip the user between my...
2
1406
by: Simon Harvey | last post by:
Hi all, Is there any easy way to check a field for calues that have changed on a post back. So the page is sent to the user, the user changes some values and I need to know which ones changed. Is the only way to do this to go through all the fields and check them against their old values. In which case, would I need to store the values in
4
2766
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been lost and show an explanatory message before restarting the session. Rather than tagging a 'session in progress' flag on the end of every request querystring I'd like to detect it using data sent in every request. One idea I had was that when...
7
1858
by: Simon Harvey | last post by:
Hi everyone, I'm having a frustrating problem and I don't know how to fix it without totally redoing a very complicated couple of pages on my site. I really hope some kind soul can help me :-) Its a very simple situation: I have 1 page that serves to create and update users and another page to add roles to the user.
7
1675
by: Markus McGee | last post by:
Hi all, I have a quick question...I believe. On my web page, call it page A, I have a drop downlist with runat server enabled. When the drop downlist change event occurs it repopulates a table depending on the value selected on page A. After I redirect page A to some other page, call it page B, and use the IE Back button to change my selection on the page A the page is forwarded to page B without rebuilding the table on page A and...
12
6995
by: ACaunter | last post by:
Hi all, I was wondering how i could write some code which would automatically open the Login Page once the session has expired? -- AdamPC@hotmail.com
5
1453
by: Russell | last post by:
Hi all, I have a web page(a) that has a link to another web page(b). Now, on the page load event of web page(b), I am doing the following: Response.redirect("./test.pdf") This pdf, if the user copies the url, can go back to it after they have logged out of my web site. I need to delete this file. I need to find a way to detect the web page is closing so I can delete the pdf file.
5
1837
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is populated) is from several different tables. To the user, of course, this is not seen. Scenario: After the page is populated, assume a change is made to the form and the user hits update. The page then goes back, reads the database for that record...
3
6247
by: whapts3 | last post by:
I'm putting together a rather dynamic page (AJAX/all-that-mess). So... to go between different sorts of content on the page, I have it set up something like this. <a href="#10" onclick="loadFragment()"> ... </a> <a href="#20" onclick="loadFragment()"> ... </a> where loadFragment is a function which does something based on the #20 which is now appended to the document's .location.
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.