473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

proper ways for empty link

if i want to have a empty link, which way is more proper?

<a href="">
<a href="#">
<a href="javascript:void(0);">

Xah
xa*@xahlee.org
∑ http://xahlee.org/

Nov 23 '05 #1
17 30592
Els
Xah Lee wrote:
if i want to have a empty link, which way is more proper?

<a href="">
<a href="#">
<a href="javascript:void(0);">


How about <a> ?
It's not a link really, but then again, I have no idea why one would
need an empty link...
Can you elaborate on what you are actually trying to achieve?

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Nov 23 '05 #2
"Xah Lee" <xa*@xahlee.org> wrote:
if i want to have a empty link, which way is more proper?
Why would you want to have an empty link?
<a href="">
This is a reference to the document itself.
<a href="#">
This is a reference to the start of the current document.
<a href="javascript:void(0);">


This is undefined; javascript: URLs are unregistered.

You could create a self-referencing link, too:
<a name="foo42" href="#foo42">

I suppose you want to have an "empty" link so that you can make something
clickable, triggering some scripted events, without making it a link.
The simple answer is: don't.

Make it a link that points to an address that contains a useful replacement
for the functionality, if it is relevant.

<a href="#nojs" onclick="foo(); return false">
.. . .
<h2 id="nojs">Something</h2>
<p>Put here something useful.</p>

If your piece of HTML code has been _generated_ with JavaScript, so that the
element does not appear if JavaScript is off, use href="#" but make sure your
event handler returns false, so that the href will never be used (it could be
harmful if it caused a movement to the start of the document).

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Nov 23 '05 #3
VK

Xah Lee wrote:
if i want to have a empty link, which way is more proper?

<a href="">
<a href="#">
<a href="javascript:void(0);">
You may want to read this extensive (and rather intensive) discussion
on this very question here:
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/4d2e99b2a8bdbbd2/b595a7a81b0a62a3>
From the *listed* options I personally would stay with:

<a href="javascript:void(myFunction())">

<a href=""> and <a href="#"> will lead to page shift/scroll if the page
is long enough on older browsers.

Nov 23 '05 #4
VK wrote:
From the *listed* options I personally would stay with:

<a href="javascript:void(myFunction())">


Of the listed options, this is the _worst_.

There is no reason to use this as opposed to:
<a href="javascript_required.html" onClick="myFunction(); return
false;">link</a>

See "Using onClick in <A> tags" in
http://www.JavascriptToolbox.com/bestpracties/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 23 '05 #5
Xah Lee a écrit :
if i want to have a empty link, which way is more proper?

<a href="">
<a href="#">
<a href="javascript:void(0);">

Xah
xa*@xahlee.org
∑ http://xahlee.org/


Your question is as logical, coherent as asking
- how to have a table without any table cells
- how to have a paragraph without any content
- how to have some kind of structure without any content or without any
functionality or without any purpose

A link should always be a link otherwise you're misusing such HTML element.

Gérard
--
remove blah to email me
Nov 23 '05 #6
In our last episode,
<11*********************@g44g2000cwa.googlegroups. com>,
the lovely and talented Xah Lee
broadcast on comp.infosystems.www.authoring.html:
if i want to have a empty link, which way is more proper? <a href="">
<a href="#">
<a href="javascript:void(0);">


This question makes no sense. Tell us what it is you are
really trying to do.
--
Lars Eighner us****@larseighner.com http://www.larseighner.com/
"Shhh! Be vewwy, vewwy quiet! I'm hunting Muswims!"
- President Elmer Bush
Nov 23 '05 #7
Gérard Talbot wrote:
Xah Lee a écrit :
if i want to have a empty link, which way is more proper?
- - Your question is as logical, coherent as asking
- how to have a table without any table cells
- how to have a paragraph without any content
- how to have some kind of structure without any content or without any
functionality or without any purpose


Well, logically, it's not quite the same. The question apparently meant
"functionally empty", i.e. a link that does not work as a link, as
opposite to an element with no content. A link that is empty in the
latter sense, <a href="something"></a>, is syntactically correct but
usually nonsensical - though it might be used to fool search engines,
and there is no law against browsers letting users to follow such a link.

A table without any table cells, on the other hand, is syntactically
incorrect (invalid), since a <table> element must contain at least one
<tr> element, which in turn must contain at least one <th> or <td>
element. The cell could be empty, though (<td></td>).

A paragraph without any content, <p></p>, is syntactically correct,
though the HTML spec explicitly says that it should not be used.
Actually, the common formatting trick is not <p></p> but <p>&nbsp;</p>,
which has content syntactically, but not semantically.

Followups trimmed to ciwah.
Nov 23 '05 #8
Jukka K. Korpela wrote:
"Xah Lee" <xa*@xahlee.org> wrote:
<a href="">
This is a reference to the document itself.


As specified in RFC3986, subsection 4.4.
<a href="#">


This is a reference to the start of the current document.


Actually, this known user agents' behavior is not a specified one.
<a href="javascript:void(0);">


This is undefined;


It is not, at least by use. `javascript:' URIS are designed to return
(HTML) documents from script code and no known HTML user agent capable
of client-side JS returns a document when the `undefined' value is used.
javascript: URLs are unregistered.


However, they exist. Not to be used for this purpose, though.

BTW: I would call them URIs. We have an unspecified URI scheme here.
AFAIK there is no general registry of URI schemes; there are definitions,
maybe (attempts at) specifications (such as RFCs).

The closest thing to a reference I could find is
<http://www.w3.org/TR/WCAG20-SCRIPT-TECHS/#js-uri>
PointedEars
Nov 23 '05 #9
Thomas 'PointedEars' Lahn wrote:
javascript: URLs are unregistered.
However, they exist. Not to be used for this purpose, though.

BTW: I would call them URIs.


<javascript:some(); js_code(2 * 23 / 35);> is certainly not an URI, and I
have never seen JS code properly encoded (and I doubt that there is broad
browser support for this).
We have an unspecified URI scheme here.
AFAIK there is no general registry of URI schemes; there are definitions,
maybe (attempts at) specifications (such as RFCs).


<http://www.iana.org/assignments/uri-schemes>
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Nov 23 '05 #10
On Fri, 18 Nov 2005 17:38:49 -0600, "Matt Kruse"
<ne********@mattkruse.com> wrote:


See "Using onClick in <A> tags" in
http://www.JavascriptToolbox.com/bestpracties/


Typo. Try:

< http://www.javascripttoolbox.com/bestpractices/ >

Nick

--
Nick Theodorakis
ni**************@hotmail.com
contact form:
http://theodorakis.net/contact.html
Nov 23 '05 #11
Lars Eighner <us****@larseighner.com> writes:
This question makes no sense. Tell us what it is you are
really trying to do.


Have a look at Xah Lee's many postings to other groups such as comp.lang.ruby,
comp.lang.python, comp.lang.perl.misc, and I'm sure many others.

He's trying to do here the same as he does everywhere: Start an argument.

Please, don't feed the troll.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Nov 23 '05 #12
VK

Sherm Pendley wrote:
Please, don't feed the troll.


It's already eaten ;-)

<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/4d2e99b2a8bdbbd2/b595a7a81b0a62a3>

Nov 23 '05 #13
Benjamin Niemann wrote:
Thomas 'PointedEars' Lahn wrote:
javascript: URLs are unregistered. However, they exist. Not to be used for this purpose, though.
BTW: I would call them URIs.


<javascript:some(); js_code(2 * 23 / 35);> is certainly not an URI,


True, there is no set of productions in RFC3986 that could produce that.
It is also no URL. How do you call it then? (You don't, I guess ;-))
and I have never seen JS code properly encoded
I have, seldom.
(and I doubt that there is broad browser support for this).


I think there is. This ... scheme has been around in script-enabled user
agents since NN 2.0 (March 1996). Try javascript:%22%40%22; for that
matter. There is even an exploit that successfully includes and uses
such an encoded string of script code in non-href attribute values.
We have an unspecified URI scheme here.
AFAIK there is no general registry of URI schemes; there are definitions,
maybe (attempts at) specifications (such as RFCs).


<http://www.iana.org/assignments/uri-schemes>


D'oh, somehow I knew I should've checked IANA first. Thanks.
PointedEars
Nov 23 '05 #14
"Xah Lee" <xa*@xahlee.org> writes:
if i want to have a empty link, which way is more proper?


I wonder why you need a empty link?
Nov 23 '05 #15
Thomas 'PointedEars' Lahn said the following on 11/19/2005 8:23 AM:
Jukka K. Korpela wrote:

"Xah Lee" <xa*@xahlee.org> wrote:
<snip>
<a href="javascript:void(0);">
This is undefined;

It is not, at least by use.


Usage does not define anything. The javascript: URL is undefined in any
standard. How the browser behaves with it is just like it does with
href="#" - Its up to the browser itself.
`javascript:' URIS are designed to return (HTML) documents from script code and no known HTML user agent capable
of client-side JS returns a document when the `undefined' value is used.

javascript: URLs are unregistered.

However, they exist. Not to be used for this purpose, though.


That doesnt make them defined. They are undefined and as such best left
alone.
BTW: I would call them URIs. We have an unspecified URI scheme here.
Unspecified and thus undefined.
The closest thing to a reference I could find is
<http://www.w3.org/TR/WCAG20-SCRIPT-TECHS/#js-uri>


<quote>
The javascript: URI space should not be used. All ECMAScript should be
designed to degrade gracefully when script is not supported, and
javascript: URIs necessarily break that graceful degradation.
</quote>

But it does nothing towards defining that URI space.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

Nov 23 '05 #16
snnn said the following on 11/21/2005 12:22 AM:
"Xah Lee" <xa*@xahlee.org> writes:

if i want to have a empty link, which way is more proper?

I wonder why you need a empty link?


Maybe because that is what he mistakenly thinks he needs?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #17
snnn <sn**@bbs.cumt.edu.cn.null> writes:
"Xah Lee" <xa*@xahlee.org> writes:
if i want to have a empty link, which way is more proper?


I wonder why you need a empty link?


I *highly* recommend searching Google Groups for "Xah Lee"'s posting history
before taking any of his questions too seriously.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Nov 23 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: stanio | last post by:
As part of a thread on netscape.public.dev.css a guy (Gus Richter) tries to convince me <a><span></span></a> is not an empty anchor: > Of course the <p></p> is empty and in the following; > ...
14
by: Xah Lee | last post by:
if i want to have a empty link, which way is more proper? <a href=""> <a href="#"> <a href="javascript:void(0);"> Xah xah@xahlee.org ∑ http://xahlee.org/
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.