[thelist] safe js

Carl Meyer cjmeyer at npcc.net
Wed Mar 17 14:49:14 CST 2004

hi Manuel,

On 17 Mar 2004, Manuel González Noriega wrote:
> <a href="foo.html" onclick="foo();return false;"
> onkeypress="foo();return false;">
> function foo() {
> if (!document.getElementById) { return; }
> So, i've got 1 and 2 covered nicely and need help with 3. Is there a way
> i can make old browsers ignore the onclick and fallback to the href?

Why don't you simply return true/false from your foo() function instead of
forcing the "return false" in your attribute?  Then return true if the
browser fails getElementById (or any other test), and return false if the
function succeeds:

<a href="foo.html" onclick="return foo()" onkeypress="return foo()">

function foo() {
  if (!document.getElementById) { return true; }
  // blah blah blah
  return false;



More information about the thelist mailing list