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-16)

0 views
Skip to first unread message

FAQ server

unread,
Mar 15, 2010, 8:00:03 PM3/15/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.

Stefan Weiss

unread,
Mar 15, 2010, 8:09:03 PM3/15/10
to
On 16/03/10 01:00, FAQ server wrote:
> -----------------------------------------------------------------------
> FAQ Topic - I have <a href="javascript:somefunction()"> what
> ... ?
> -----------------------------------------------------------------------

The same FAQ item was posted 4 days ago. The FAQ about client side file
system access was also repeated after only 4 days. Is there something
wrong with the FAQ autoposter script?

--
stefan

Peter Billam

unread,
Mar 16, 2010, 1:04:54 AM3/16/10
to
On 2010-03-16, FAQ server <javas...@dotinternet.be> wrote:
>
> 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.

It would be helpful if this code could also include how to set
the colour of the text to the default link-colour, and to change
the arrow to the default you-are-hovering-over-a-link pointer...

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

This doesn't look right. Two faq/s in a row ?

Regards, Peter

--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html

Thomas 'PointedEars' Lahn

unread,
Mar 16, 2010, 8:21:04 AM3/16/10
to
Peter Billam wrote:

> On 2010-03-16, FAQ server <javas...@dotinternet.be> wrote:
>> 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.
>
> It would be helpful if this code could also include how to set
> the colour of the text to the default link-colour, and to change
> the arrow to the default you-are-hovering-over-a-link pointer...

It would not. Both are unnecessary here.

>> http://jibbering.com/faq//faq/example/jsuri/
>
> This doesn't look right. Two faq/s in a row ?

ACK. And the <`> issue should finally be fixed as well.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300...@news.demon.co.uk> (2004)

Peter Billam

unread,
Mar 16, 2010, 7:20:37 PM3/16/10
to
On 2010-03-16, Thomas 'PointedEars' Lahn <Point...@web.de> wrote:

> Peter Billam wrote:
>>> ` <a href="something.html" onclick="somefunction();return false"> `
>> It would be helpful if this code could also include how to set
>> the colour of the text to the default link-colour, and to change
>> the arrow to the default you-are-hovering-over-a-link pointer...
>
> It would not. Both are unnecessary here.

ACK: the fallback href="something.html" provides those services :-)

0 new messages