[thelist] safe js

Hassan Schroeder hassan at webtuitive.com
Wed Mar 17 11:31:19 CST 2004


Manuel González Noriega wrote:

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

> function foo() {
> if (!document.getElementById) { return; }
> // Blah, blah, blah...
> }

> 1 Non js devices will use the foo.html page 
> 2 Modern browsers, js enabled will execute foo(), pass the
> document.getElementById test and go along OK.
> 3. Old browsers with js enabled but failing the getElementById test,
> won't do anything
> 
> 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?

Yeah, don't hardwire the "return false" :-) Something like this --

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

function foo()
{
     var result = true;
     if (document.getElementById)
     {
         // Blah, blah, blah...
         result = false;
     }
     return result;		
}

And note: there's only *one* place in the code -- the very end --
that the result is returned, though the *value* to be returned can
be set multiple places; generally considered easier to troubleshoot...

FWIW,
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.




More information about the thelist mailing list