[Javascript] Safari issues or better saying poor programming issues

David Lovering dlovering at gazos.com
Wed Mar 31 09:13:59 CDT 2010


I would like to offer an uninformed guess as to why the onClick works in
this context while the onFocus doesn't (at least consistently, across
multiple browsers).

The onFocus event occurs as soon as the cursor sweeps across a focusable
object, and has nothing to do with when the value and/or internal state
variables are changed.  The onClick on the other hand forces a 'select'
state on the object, assuming it isn't already deactivated - as well as
launching whatever scripts are tied to the event handler.  This is due in
part to a subtle confusion between browsers as to what 'focus' and 'select'
actually means - some don't lock focus until a select is enacted, while
others are more general and adhere better to W3C DOM guidelines.

When an onClick occurs it generally locks both focus and select, as well as
creating the 'click' event itself.  [Assuming again the object hasn't
already been disabled or rendered unfocusable].  Then it is merely a matter
of sorting out the precedence of which comes first - onClick, onSelect, or
onFocus.  If you want to force a uniform interpretation of 'focus' you can
create your own equivalent by doing a real-time cursor coordinate readout
and then pulling up the window object at that coordinate, but that is hugely
expensive in terms of CPU event management and is not considered good
programming practice.

This pretty much works everywhere, across every browser.  It should be noted
that some (like IE7 and beyond) use somewhat proprietary DOM notation which
may not port everywhere - but since the Safari people also use some
marginally proprietary constructs [probably to facilitate carry-over from
the earlier Applescript event handlers], they are not entirely blameless
either.  Firefox and others have their own issues, although Firefox at least
allows you to get in and monkey with the config settings for better
adherence to the model of choice you envision.  IE7+ can also be tweaked,
but usually at some level requires resedit to make everything 'stick'.

The best way to be absolutely portable in the Javascript domain is to write
an onLoad preamble that senses the browser platform, and then customizes the
event particulars appropriately with handlers that take these oddities into
consideration.  Actually, I lie - the best way ever is to have every browser
conform exactly and completely with the same standard down to the tiniest
detail; but short of a Second Coming I think the chances of that happening
are slim to none.  A good example of this dichotomy is the classic 'keyval'
issue, which has historically been handled in quite different ways in nearly
every browser.

-- Dave Lovering

-----Original Message-----
From: javascript-bounces at lists.evolt.org
[mailto:javascript-bounces at lists.evolt.org] On Behalf Of MEM
Sent: Wednesday, March 31, 2010 2:35 AM
To: JavaScript List
Subject: Re: [Javascript] Safari issues or better saying poor programming
issues

2010/3/30 MEM <talofo at gmail.com>

> Hello all,
>
> I'm newbie into javascript and with this speed, I will always be... so I'm
> sorry for this strange solution to work with disabled and enabled inputs,
if
> you can share a better way, I can digg in.
> Anyway, can I please have your help:
>
> I have issues on Safari display for the following code:
>
> http://pastebin.com/imenHbWB
>
> The linked js file contains to the document above has the following lines:
>
> function activaInput()
> {
>     document.candidaturaOnline.txtOutro.disabled=false;
> }
>
> function desactivaInput()
> {
>     document.candidaturaOnline.txtOutro.disabled=true;
> }
>
>
>
> What it doesn't do is, it doesn't allow the user to write on the input box
> with the id txtOutro, when the radio button with the id outro has focus.
>
> I'm on Safari 4.0.5
>
> Both, the HTML and CSS are validated on w3c.
>
>
> What could be the issue?
> Márcio
>
>
>

By changing the onFocus event listener (can we call it like this?) TO a
onClick event listener on the radio buttons, it works cross browser.

Why is this?

Best regards,
Márcio
_______________________________________________
Javascript mailing list
Javascript at lists.evolt.org
http://lists.evolt.org/mailman/listinfo/javascript



More information about the Javascript mailing list