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.
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.
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/
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.
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.
"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/Bookmarklet> could 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.
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/Bookmarklet> could 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.
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>
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.
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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
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.
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.
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.
> 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
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.
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.
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
Yes, if the context is not ActionScript specific.
Richard.
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.