Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FAQ Topic - I have <a href="javascript:somefunction()"> what ... ? (2010-03-12)

1 view
Skip to first unread message

FAQ server

unread,
Mar 11, 2010, 7:00:02 PM3/11/10
to
-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"> what
... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad idea.
The ` javascript: ` pseudo protocol was designed to replace the
current document with the value that is returned from the expression.
For example:

<a href="javascript:'&lt;h1&gt;' + document.lastModified + '&lt;/h1&gt;'">lastModified</a>

will result in replacing the current document with the value
returned from ` document.lastModified `, wrapped in an ` <h1> `
tag.

When the expression used evaluates to an ` undefined ` value
(as some function calls do), the contents of the current page are not
replaced. Regardless, some browsers (notably IE6) interpret this as
navigation and will enter into a 'navigation' state where GIF
animations and image swaps will stop working.

It is also possible for IE to be configured such that it supports
javascript but not the ` javascript: ` protocol. This results
in the user seeing a protocol error for ` javascript: ` URIs.

The ` javascript: ` pseudo protocol creates accessibility and
usability problems. It provides no fallback for when the script is not
supported.

Instead, use
` <a href="something.html" onclick="somefunction();return false"> `
where ` something.html ` is a meaningful alternative. Alternatively,
attach the ` click ` callback using an event registry.

http://jibbering.com/faq//faq/example/jsuri/

http://www.useit.com/alertbox/20021223.html


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

Dr J R Stockton

unread,
Mar 14, 2010, 6:34:54 PM3/14/10
to
In comp.lang.javascript message <4b998409$0$283$1472...@news.sunsite.dk
>, Fri, 12 Mar 2010 00:00:02, FAQ server <javas...@dotinternet.be>
posted:

>-----------------------------------------------------------------------
>FAQ Topic - I have <a href="javascript:somefunction()"> what
>... ?
>-----------------------------------------------------------------------
>
>Whatever the rest of your question, this is generally a very bad idea.
>The ` javascript: ` pseudo protocol was designed to replace the
>current document with the value that is returned from the expression.
>For example:
>
><a href="javascript:'&lt;h1&gt;' + document.lastModified + '&lt;/h1&gt;
>'">lastModified</a>
>
>will result in replacing the current document with the value
>returned from ` document.lastModified `, wrapped in an ` <h1> `
>tag.

Response delayed; AIOE rejected the first attempt for having HTML in the
Subject.

The result is browser-dependent, and probably dependent on whether the
browser is reading from a server or directly from a test file. The
following should be safer, and less confusing for those unfamiliar with
the variations in what lastModified does.

<a href="javascript:'&lt;h1&gt;' + 2*3 + '&lt;/h1&gt;'">SIX</a>

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Grandson-Of-RFC1036 is released. RFC 5536 Netnews Article Format is a
subset of Internet Message Format which is described in RFC 5532. The
RFCs are read together to determine standard Netnews article format.

0 new messages