[Javascript] Stopping default action
Bill Moseley
moseley at hank.org
Fri Mar 31 00:43:41 CST 2006
On Thu, Mar 30, 2006 at 06:48:32PM -0500, Mike Dougherty wrote:
> I just had a reason to research this myself...
>
> http://www.gerd-riesselmann.net/archives/2005/03/a-firefox-javascript-bug
>
> Read the author's thoughts describing your problem, then see the first
> comment for the (obvious?) solution. :)
Thanks. I also came across that during my wild google chase for
ideas.
So I'm using this to set my ajax events:
function updater( linkID, target ) {
var el = $(linkID);
var url = el.href;
var my_update = function(e) {
e.preventDefault();
new Ajax.Updater( target, url,
{
evalScripts: true,
method: 'get',
requestHeaders: ['X-Ajax-Updater', 'ajax_table']
});
return false;
}
Event.observe( linkID, 'click', my_update, 'false' );
}
Not thrilled about using evalScripts. It's needed to reset the events
after the ajax update (the update replaces those elements). That
requires the ajax response to include a <script> section with fresh
calls to updater().
Right now none of my ajax updates change the links (or their ids) so
I'm thinking about saving each [linkID, target] on an array, and then
use the onComplete feature of Ajax.Updater to reload those events
after the ajax update. That would avoid having to send <script> in
the ajax response.
But, then there's a risk I might call updater() again for a now
non-existent link, or add another event for a link that was not
updated by the ajax call -- ending up with multiple events.
Kind of a bother for just trying to get rid of my inline onclicks. ;)
Separation of behavior and structure, so they say...
--
Bill Moseley
moseley at hank.org
More information about the Javascript
mailing list