473,546 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

manual focus vs. focus()

Hi,

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

if(window.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' 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.foc us()?

Thanks!
Jeff

May 20 '07 #1
4 2425
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.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' 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.foc us()?
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...@y ahoo.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.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' 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.foc us()?

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.getEle mentById('ancho r_node');
if(window.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' focus',
gotFocus, false);
setTimeout(setF ocus, 5000);
}

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

function setFocus() {
var anchor_node = document.getEle mentById('ancho r_node');
anchor_node.foc us();
}

</script>
</head>
<body onload="setList en()">
<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.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' focus',gotFocus , false);
what if a browser supports both attachEvent and addEventListene r ??

May 21 '07 #4
On May 20, 7:59 pm, "scripts.contac t" <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.attac hEvent) anchor_node.att achEvent('onfoc us', gotFocus);
if(window.addEv entListener) anchor_node.add EventListener(' focus',gotFocus , false);

what if a browser supports both attachEvent and addEventListene r ??
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
2207
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 time and there is also a check on that. If time is empty return error message. Again the explorer returns error message and then shifts the focus...
2
3081
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 Mozilla-only problem) I'm capturing the focus and blur events for the document, updating a
3
6877
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 doesnt give any errors, the focus just doesnt change.
17
3837
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 record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the...
1
2226
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 page to Aspx2 which has a Datagrid. PageLoad of Aspx2 displays the DataGrid with existing data filled in and shows a new row (set of text boxes) in...
4
3934
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 textboxes and a checkbox. The behaviour I want from my app is as follows:- When the textbox (which is prior in tab order to the tab control) has...
11
7320
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 1.7.12 (linux kubuntu). It does work with konqueror. It seems to work with firefox on windows but not with IE (not completly sure though).
7
11907
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' and it steals the focus from the user's current application. How can I prevent the hidden WebBrowser from stealing focus? (And better yet can I...
4
67974
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 these forms that may make one succeed and another fail? In particular, this.window.focus() fails in Opera 9.10 with an "object not found", and...
0
7694
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. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7792
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...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5080
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...
0
3491
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
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
0
747
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...

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.