By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

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

P: n/a
-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol. It was designed so that a
function could return a new page. For example:
`` javascript:"<p>Hello</p>" ''.
Using it simply to call a function when a link is clicked causes
an error in user agents that do not support javascript, or have
javascript disabled. Instead, use
`` <a href="something.html" onclick="somefunction();return false"''
where something.html is a meaningful alternative. Alternatively,
place the onclick event on another element so that users without
JavaScript aren't even aware that it does anything.

http://www.useit.com/alertbox/20021223.html
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Sep 5 '06 #1
Share this Question
Share on Google+
19 Replies


P: n/a
VK

FAQ server wrote:
-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol.
Unless you are programming a bookmarklet (see the definition). In such
case it is always a good idea to enclose the rest of your code into
"void" operator to ensure that the UA will never "navigate" to the
output of your code (in case of error for example):
a href="javascript:void(the rest of your code)"
The usage of javascript: pseudo-protocol for pseudo-links (thus links
with the only purpose to trig some script execution on the same page)
should be avoided.

Sep 6 '06 #2

P: n/a
VK said the following on 9/6/2006 2:29 AM:
FAQ server wrote:
>-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol.

Unless you are programming a bookmarklet (see the definition). In such
case it is always a good idea to enclose the rest of your code into
"void" operator to ensure that the UA will never "navigate" to the
output of your code (in case of error for example):
a href="javascript:void(the rest of your code)"
That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.
The usage of javascript: pseudo-protocol for pseudo-links (thus links
with the only purpose to trig some script execution on the same page)
should be avoided.
Then why the nonsensical crap about wrapping it in a void operator?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 7 '06 #3

P: n/a
VK
Randy Webb wrote:
That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.
This FAQ was written eons ago, before bookmarklets became
well-established and popular technologies. Therefore it denies the use
of ...href="javascript:.. as such. It is like take the rule "do not
cross the street unless you see the green light" and made of it "do not
cross the street, never..."

clj may try to insist on some preferred ways of coding, but an attempt
to "close" an entire technologies seems funny.
Then why the nonsensical crap about wrapping it in a void operator?
That was explained many times in this group, and first time by Brendan
Eich in Netscapes's JavaScript reference (1.2 and 1.3). You may want to
search this group archives.

Sep 7 '06 #4

P: n/a
VK wrote:
Randy Webb wrote:
That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.

This FAQ was written eons ago, before bookmarklets became
well-established and popular technologies.
That is not true. Bookmarklets have been popular for a very long time
now.
Therefore it denies the use
of ...href="javascript:.. as such.
What has href="javascript:... got to do with bookmakrlets?
It is like take the rule "do not cross the street unless you see the
green light" and made of it "do not cross the street, never..."
Halfwit.
clj may try to insist on some preferred ways of coding, but an
attempt to "close" an entire technologies seems funny.
Halfwit.
Then why the nonsensical crap about wrapping it in a void operator?

That was explained many times in this group,
Your claims of mystical powers associated with the void operator have
never been explained by you (and the other explanations stress your
insanity).
and first time by Brendan Eich in Netscapes's JavaScript reference
(1.2 and 1.3).
What makes you think that Brendan Eich wrote the references?
You may want to search this group archives.
There is no need as Randy know the mechanism so he does not need to be
chanting mystical incantations at the issue like you do.

Richard.

Sep 7 '06 #5

P: n/a
VK

Richard Cornford wrote:
What has href="javascript:... got to do with bookmakrlets?
"What JavaScript has to do with client-side scripting?"

Is this today the Day of Stupid Questions? :-0 :-)

You may want to check what bookmarlets are and how are they used (just
to eliminate a possibility that we are talking about different entities
with the same name).

<http://en.wikipedia.org/wiki/Bookmarkletcould be used - not as the
most authoritative official source but as the most plain-worded yet
informative.

<snip>
Halfwit.
Full dumb.
(my response in celebration of you calling me "halfwit" for 50th time).
Your claims of mystical powers associated with the void operator have
never been explained by you (and the other explanations stress your
insanity).
There is no mystical power behind "void" operator but it is boring to
explain it again and again just to hear "so why use void operator
here?" in just few weeks later.
OK, for Nth time: to avoid "navigation" to the bookmarlet output, dumb
a** !
And this output may happen if the bookmarklet execution breaks. Just
search this group for explanations and samples .
What makes you think that Brendan Eich wrote the references?
See the very top of this post.

Sep 7 '06 #6

P: n/a
VK wrote:
Richard Cornford wrote:
What has href="javascript:... got to do with bookmakrlets?

"What JavaScript has to do with client-side scripting?"
Halfwit.
Is this today the Day of Stupid Questions? :-0 :-)
A question does not become stupid just because it goes over your head.
Bookmarklets are stored by the browser and executed a javascript
pseudo-protocol URLs. So questioning what that has to do with the
seriously inadvisable practice of using a javascript pseudo protocol
URL to an HREF attribute is reasonable. Although there may be little
point in asking you it as your thought process is too clouded for you
to understand.
You may want to check what bookmarlets are and how are they
used (just to eliminate a possibility that we are talking about
different entities with the same name).
You may want to read the question asked.
<http://en.wikipedia.org/wiki/Bookmarkletcould be used - not as the
most authoritative official source but as the most plain-worded yet
informative.
<quote cite="http://en.wikipedia.org/wiki/Bookmarklet">
A bookmarklet is a small JavaScript program that can be stored as a URL
within a bookmark in most popular web browsers,
</quote>

So what has that to do with values of HREF attributes?
<snip>
Halfwit.

Full dumb.
(my response in celebration of you calling me "halfwit" for 50th time).
Halfwit.
>Your claims of mystical powers associated with the void operator have
never been explained by you (and the other explanations stress your
insanity).

There is no mystical power behind "void" operator but it is boring to
explain it again and again just to hear "so why use void operator
here?" in just few weeks later.
You never have explained. All you do is post fictional non-sense and
ignore the people telling you it is nonsense.
OK, for Nth time: to avoid "navigation" to the bookmarlet output,
The loading of content derived from the expression evaluated in a
javascript pseudo-protocol HREF or bookmarklet it is only necessary
that the value be the Undefined type. There are many expressions that
will evaluate as Undefined that are not void operations. Indeed for
bookmarklets of any complexity an inline function call would be
preferable to a void operation as the contained scope avoids the
bookmarklet interfearing with the existing page's scripts.
dumb a** !
Halfwit.
And this output may happen if the bookmarklet execution breaks.
It will not.
Just search this group for explanations and samples .
Halfwit.
>What makes you think that Brendan Eich wrote the references?

See the very top of this post.
You mean the place where you suggest that some questions may be stupid?
The question is reasonable as the document does not appear to credit
any author and user guides and references for software are very rarely
well-written by the authors of the code (as the code authors understand
how everything works and so have little idea how to promote that
understanding in others).

Richard.

Sep 7 '06 #7

P: n/a
VK

Richard Cornford wrote:
Bookmarklets are stored by the browser and executed a javascript
pseudo-protocol URLs. So questioning what that has to do with the
seriously inadvisable practice of using a javascript pseudo protocol
URL to an HREF attribute is reasonable.

I would insistently suggest to read the linked Wiki resource and *add*
a bookmarklet or two to your browser. How do you think people provide
bookmarklets on their pages and how their visitors add them to
Bookmarks/Favorites? Concentrate on this thought and the rest will come
to you by itself.

I take back "dumb a**" as too much, I stay on "full dumb" out of the
eye-for-eye principle.

<snip>
Halfwit.
Full dumb

<snip>

Sep 7 '06 #8

P: n/a
VK wrote:
Richard Cornford wrote:
>Bookmarklets are stored by the browser and executed a javascript
pseudo-protocol URLs. So questioning what that has to do with the
seriously inadvisable practice of using a javascript pseudo protocol
URL to an HREF attribute is reasonable.

I would insistently suggest to read the linked Wiki resource and
*add* a bookmarklet or two to your browser. How do you think
people provide bookmarklets on their pages and how their visitors
add them to Bookmarks/Favorites? Concentrate on this thought
and the rest will come to you by itself.
How people may create bookmarklets is irrelevant to what a bookmarklet
is. I usually create them by copying code into the appropriate field on
the properties dialog of a copied link.
I take back "dumb a**" as too much, I stay on "full dumb" out of the
eye-for-eye principle.
<snip>

It does not matter which words you use when being incoherent.

Richard.

Sep 7 '06 #9

P: n/a
JRS: In article <44***********************@news.sunsite.dk>, dated Tue,
5 Sep 2006 23:00:01 remote, seen in news:comp.lang.javascript, FAQ
server <ja********@dotinternet.beposted :
>-----------------------------------------------------------------------
FAQ Topic - I have <a href="javascript:somefunction()"what ... ?
-----------------------------------------------------------------------

Whatever the rest of your question, this is generally a very bad
use of the javascript pseudo protocol. It was designed so that a
function could return a new page. For example:
`` javascript:"<p>Hello</p>" ''.
Using it simply to call a function when a link is clicked causes
an error in user agents that do not support javascript, or have
javascript disabled. Instead, use
`` <a href="something.html" onclick="somefunction();return false"''
where something.html is a meaningful alternative. Alternatively,
place the onclick event on another element so that users without
JavaScript aren't even aware that it does anything.
FAQ has inconsistent capitalisation of javascript. I'd prefer
Javascript except in javascript: and in c.l.j. - I think.

`` javascript:"<p>Hello</p>" ''
^^ ^^
I dislike the appearance of those outer quotes.

There are in FAQ 4.24 several instances of " being
used to quote HTML attributes. It would be better
to use ' instead for javascript:"<p>Hello</p>"
I don't know why what follows javascript: can be either a string with
implicit document.write or ordinary code.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 7 '06 #10

P: n/a
VK said the following on 9/7/2006 8:53 AM:
Randy Webb wrote:
>That is, without a doubt, bad advice. The better advice is to *never*
put javascript: in an href, put it in an onclick event handler which is
*precisely* what the FAQ says to do.

This FAQ was written eons ago, before bookmarklets became
well-established and popular technologies.
I am not going to explain something to you that Richard has already
wasted enough time trying to get you to comprehend. Bookmarklets are
irrelevant to HREF issues that the FAQ addresses.
Therefore it denies the use of ...href="javascript:.. as such.
No, it advises not to use href="javascript: in a web based environment.
Nothing more, nothing less. Your failure to comprehend that is evident.
It is like take the rule "do not cross the street unless you see the
green light" and made of it "do not cross the street, never..."
I don't cross streets when I see the green light, I cross when it is red
so that the traffic is stopped. If you want to push it, I cross on a
white light when the signal tells me to.

You should refrain from arguing logic because you don't understand it.
clj may try to insist on some preferred ways of coding, but an attempt
to "close" an entire technologies seems funny.
"entire technology"? Where does the FAQ oppose Bookmarklets? It doesn't.
That is another fantasy of yours. Nowhere has anybody said don't use
Bookmarklets. I use them daily. But not one uses javascript: in an HREF
attribute.
>Then why the nonsensical crap about wrapping it in a void operator?

That was explained many times in this group, and first time by Brendan
Eich in Netscapes's JavaScript reference (1.2 and 1.3). You may want to
search this group archives.
You should become a comedian.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 7 '06 #11

P: n/a
VK

Randy Webb wrote:
Bookmarklets are irrelevant to HREF issues that the FAQ addresses.
The FAQ doesn't address any particular issues. It simply explains
the only "legal" use of javascript pseudo-protocol - which is
the navigation to the script-generated content - and it calls any
other usage wrong.
it advises not to use href="javascript: in a web based environment.
Nothing more, nothing less. Your failure to comprehend that is evident.
I comprehend it perfectly and this is why I originally pointed to
another important use of javascript psi-protocol in "a web based
environment".
But if you decided to play some "Dumm and dummer" screenplay with
Richard,
I'll give one more (very simplified) hint:

<html>
<head>
<title>Bookmarklet</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<a href="javascript:
var now = new Date();
var url = 'http://www.foo.bar';
url+= '/'
+ now.getFullYear()
+ '/' + now.getMonth()
+ '/' + now.getDay()
+ '/index.html';
window.alert('You would be directed to '+url);"
title="Evergreen Link">Bookmark this to have an
evergreen link to my resource</a>
</body>
</html>

Now i) either explain that it is not javascript psi-protocol usage
in a web based environment and has nothing to do with HREF or ii)
get finally silent.
You should become a comedian.
I maybe would but cases like that are making me
to be affraid of too much of competition.

Sep 7 '06 #12

P: n/a
VK

Dr John Stockton wrote:
I'd prefer Javascript except in javascript: and in c.l.j. - I think.
Actually the language is called JavaScript (with capital J and S) and
its Microsoft version is called JScript (with capital J and S either).
That is an acceptable shortcut to say just "script" and "scripting" if
the context clearly points either to both JavaScript/JScript (general
question) or to one of these two.
There is no language called "Javascript" or "javascript". Such term
would be technically incorrect though mainly understandable.

Sep 7 '06 #13

P: n/a
"VK" <sc**********@yahoo.comwrites:
javascript psi-protocol
That's the single most compact and comprehensive summary on the topic I
have ever read. :)
--
||| hexadecimal EBB
o-o decimal 3771
--oOo--( )--oOo-- octal 7273
205 goodbye binary 111010111011
Sep 7 '06 #14

P: n/a
VK wrote:
Randy Webb wrote:
>Bookmarklets are irrelevant to HREF issues that
the FAQ addresses.

The FAQ doesn't address any particular issues. It simply
explains the only "legal" use of javascript pseudo-protocol
- which is the navigation to the script-generated content -
and it calls any other usage wrong.
>it advises not to use href="javascript: in a web based
environment. Nothing more, nothing less. Your failure to
comprehend that is evident.

I comprehend it perfectly
If true that would be the first time.
and this is why I originally pointed to another
important use of javascript psi-protocol in "a web
based environment".
It is not an "important use". Bookmarklets generally are only tools for
personal use, they have no place in the design of a serious web site.
But if you decided to play some "Dumm and dummer"
screenplay with Richard,
I'll give one more (very simplified) hint:

<html>
<snip>
</html>
Now i) either explain that it is not javascript psi-protocol
"javascript psi-protocol" is terminology that you made up off the top of
your head, and in disregard of the meaning of the components it is
constructed from.
usage in a web based environment and has nothing to do
with HREF or ii) get finally silent.
<snip>

It is a half-ass hack, so typical of you. Any competent developer would
know how to implement this server side and so create a much more
reliable result.

Richard.
Sep 7 '06 #15

P: n/a
VK wrote:
Dr John Stockton wrote:
>I'd prefer Javascript except in javascript: and in c.l.j.
- I think.

Actually the language is called JavaScript (with capital J
and S) and its Microsoft version is called JScript (with
capital J and S either). That is an acceptable shortcut to
say just "script" and "scripting" if the context clearly
points either to both JavaScript/JScript (general question)
or to one of these two.
So the many other language implementations (in Opera, NetFront,
Konqueror, etc, etc.) are not to be considered?
There is no language called "Javascript" or "javascript".
Such term would be technically incorrect though mainly
understandable.
Your guidance on terminology (like your opinions in general) is
worthless. It has long since been widely agreed that 'javascript' is an
appropriate term to use when talking of all ECMAScript implementations,
so JavaScript(tm) and JScript (and KScript, DScript or whatever) can be
used to talk about specific implementations. The usage of 'javascript'
is now common and well understood.

Richard.
Sep 7 '06 #16

P: n/a
In article <11**********************@i3g2000cwc.googlegroups. com>, VK
<sc**********@yahoo.comwrites
>
Dr John Stockton wrote:
>I'd prefer Javascript except in javascript: and in c.l.j. - I think.

Actually the language is called JavaScript (with capital J and S) and
its Microsoft version is called JScript (with capital J and S either).
That is an acceptable shortcut to say just "script" and "scripting" if
the context clearly points either to both JavaScript/JScript (general
question) or to one of these two.
There is no language called "Javascript" or "javascript". Such term
would be technically incorrect though mainly understandable.
Actually both JavaScript and JScript are registered trade marks. You are
not allowed to use either word to cover both language variants. That's
why "javascript" is a reasonable word to use when you are not talking
about a particular release of a particular company's product.

John
--
John Harris
Sep 8 '06 #17

P: n/a

Richard Cornford написав:
VK wrote:
There is no language called "Javascript" or "javascript".
Such term would be technically incorrect though mainly
understandable.

Your guidance on terminology (like your opinions in general) is
worthless. It has long since been widely agreed that 'javascript' is an
appropriate term to use when talking of all ECMAScript implementations,
so JavaScript(tm) and JScript (and KScript, DScript or whatever) can be
used to talk about specific implementations. The usage of 'javascript'
is now common and well understood.

Richard.
ActionScript in Flash is a specific implementation of ECMAScript.
Is it right to call it "javascript"?

Sep 9 '06 #18

P: n/a
sc********@gmail.com wrote:
Richard Cornford напи ав:
>VK wrote:
>>There is no language called "Javascript" or "javascript".
Such term would be technically incorrect though mainly
understandable.

Your guidance on terminology (like your opinions in general)
is worthless. It has long since been widely agreed that
'javascript' is an appropriate term to use when talking of
all ECMAScript implementations, so JavaScript(tm) and JScript
(and KScript, DScript or whatever) can be used to talk about
specific implementations. The usage of 'javascript' is now
common and well understood.

Richard.
ActionScript in Flash is a specific implementation of
ECMAScript. Is it right to call it "javascript"?
Yes, if the context is not ActionScript specific.

Richard.
Sep 10 '06 #19

P: n/a
VK said the following on 9/7/2006 5:17 PM:
Randy Webb wrote:
>Bookmarklets are irrelevant to HREF issues that the FAQ addresses.

The FAQ doesn't address any particular issues.
It doesn't? Let me give you the question that it answers:

<quote>
I have <a href="javascript:somefunction()"what
</quote>

It specifically deals with javascript: in the HREF attribute of an A
element.
It simply explains the only "legal" use of javascript pseudo-protocol - which is
the navigation to the script-generated content - and it calls any
other usage wrong.
No, it mentions it's original intended purpose. And it doesn't claim
anything to be "legal" or not. It says:

<quote>
this is generally a very bad use of the javascript pseudo protocol
</quote>

Note the word "generally" in that snippet. Do you see it? Now, please
try to understand what you read before you claim to understand what it says.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 12 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.