473,410 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

manual focus vs. focus()

Hi,

I'm attaching an onfocus event handler to an anchor tag like this:

if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',
gotFocus, false);

function gotFocus() {
alert('i got focus');
}

Is there any way to tell the difference between when this anchor is
focused by a user (perhaps by tabbing to it) as opposed to when I
programatically do it via anchor_node.focus()?

Thanks!
Jeff

May 20 '07 #1
4 2407
VK
On May 20, 12:12 pm, Jeff <jeffrey.big...@gmail.comwrote:
Hi,

I'm attaching an onfocus event handler to an anchor tag like this:

if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',
gotFocus, false);

function gotFocus() {
alert('i got focus');

}

Is there any way to tell the difference between when this anchor is
focused by a user (perhaps by tabbing to it) as opposed to when I
programatically do it via anchor_node.focus()?
Programmatical events:
1) do not re-fire for listeners
2) do not bubble (propagate)

May 20 '07 #2
On May 20, 2:40 am, VK <schools_r...@yahoo.comwrote:
On May 20, 12:12 pm, Jeff <jeffrey.big...@gmail.comwrote:
Hi,
I'm attaching an onfocus event handler to an anchor tag like this:
if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',
gotFocus, false);
function gotFocus() {
alert('i got focus');
}
Is there any way to tell the difference between when this anchor is
focused by a user (perhaps by tabbing to it) as opposed to when I
programatically do it via anchor_node.focus()?

Programmatical events:
1) do not re-fire for listeners
2) do not bubble (propagate)
I know that's true for other events, but it appears to not be true for
focus.

I've put a demonstration on this page:
http://webinsight.cs.washington.edu/...est_focus.html

After 5 seconds, the page will automatically focus on the "My Anchor"
link and it will alert "Got focus." If before that time, you put
focus on the link manually, it will also do this. The question then
is how can I distinguish these two types of gaining focus?

Thanks,
Jeff

<html>
<head>
<script>
function setListen() {
var anchor_node = document.getElementById('anchor_node');
if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',
gotFocus, false);
setTimeout(setFocus, 5000);
}

function gotFocus() {
alert('i got focus');
}

function setFocus() {
var anchor_node = document.getElementById('anchor_node');
anchor_node.focus();
}

</script>
</head>
<body onload="setListen()">
<a href="">Another Anchor</a>
<a href="" id="anchor_node">My Anchor</a>
</body>
</html>

May 20 '07 #3
On May 20, 2:12 am, Jeff <jeffrey.big...@gmail.comwrote:
Hi,

I'm attaching an onfocus event handler to an anchor tag like this:

if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',gotFocus, false);
what if a browser supports both attachEvent and addEventListener ??

May 21 '07 #4
On May 20, 7:59 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On May 20, 2:12 am, Jeff <jeffrey.big...@gmail.comwrote:
Hi,
I'm attaching an onfocus event handler to an anchor tag like this:
if(window.attachEvent) anchor_node.attachEvent('onfocus', gotFocus);
if(window.addEventListener) anchor_node.addEventListener('focus',gotFocus, false);

what if a browser supports both attachEvent and addEventListener ??
Then I guess my code is twice as broken as it is now.

May 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
2
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a...
3
by: VA | last post by:
t=document.getElementById('mytable') is a HTML table with some input fields in its cells Why doesnt t.getElementsByTagName('tr').firstChild.focus; put the focus on that text field? It...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
1
by: avnrao | last post by:
Hi, I am facing a problem with control.focus (javascript). Here is the description of the issue. 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on this, will redirect...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
11
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz...
7
by: Dave Booker | last post by:
I am using a WebBrowser object in my .NET 2.0 application, but it is not shown to the user. Every time a timer event triggers it to perform a m_WebBrowser.Navigate() I get that classic IE 'click'...
4
by: Roger | last post by:
Hi, I am confused about the differences between this.window.focus(), window.focus(), and this.focus(). I want to use the calls in a <body onload="..."tag. What are the differences between...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.