Re: [#1059] Prohibit URLs with javascript protocol

Michael Cooper wrote:

> The following is a proposal for HTML techniques. 


> Links that use the Javascript protocol, e.g.,
> 
> <a href="javascript:dosomething();">Javascript link</a>
> 
> are unusable by browsers that do not support javascript.
> 
> There should be a technique that advises authors not to use
> javascript links. Instead, they should provide an http link to a
> fallback page, and instantiate the desired script using event
> handlers. For example:
> 
> <a href="fallback.html" onactivate="dosomething()">Good link</a>

Neither HTML 4.01 nor XHTML 1.0 know an onactivate event handler thus I
don't think what you suggest as an alternative fits into a proposal for
HTML techniques.
IE 5.5 and IE 6 on Win do support an onactivate event handler, see
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onactivate.asp
but that has a different semantic, it doesn't fire when you follow the
link but instead fires when you navigate to the link.
Thus I don't think it makes sense to suggest scripters to replace
   <a href="javascript:dosomething();">Javascript link</a>
with
   <a href="fallback.html" onactivate="dosomething()">Good link</a>
you need to suggest something that is functionally equivalent which would be
   <a href="fallback.html"
      onclick="dosomething();
               if (event.preventDefault) {
                 event.preventDefault();
               }
               return false;">Good link</a>
where the script code

              if (event.preventDefault) {
                 event.preventDefault();
               }
               return false;

is necessary to prevent the browser from loading the fallback.html when
the dosomething() call works.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/

Received on Wednesday, 22 September 2004 12:48:29 UTC