Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

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

On May 20, 12:12 pm, Jeff <jeffrey.big@gmail.com> wrote:

Programmatical events:
1) do not re-fire for listeners
2) do not bubble (propagate)
On May 20, 2:40 am, VK <schools_r@yahoo.com> wrote:

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/test/test_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>
On May 20, 2:12 am, Jeff <jeffrey.big@gmail.com> wrote:

> 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 ??
On May 20, 7:59 pm, "scripts.contact" <scripts.cont@gmail.com>
wrote:

> On May 20, 2:12 am, Jeff <jeffrey.big@gmail.com> wrote:

> > 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.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc