473,796 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Empty Anchors, I can't find a W3C specification for it

Hello,
I am little surprised about the following:
<a href="#" ...

I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,
but in both cases this seems to be not valid name="#" or id=""...
And I wonder why the online validator allow this in all cases.DOCUMENT
types.

Can someone give me a definitive link to any W3C document where I can
see this is Valid? I found only some sites where the consequence would
be this is not valid.

Peter

Apr 7 '07 #1
16 5014
Scripsit La*********@gma il.com:
I am little surprised about the following:
<a href="#" ...
Just don't use them, mm'kay? But that's a practical issue. Formally, it is
well-defined.
I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,
Wrong. The href _attribute_ value is a _URL_. You need to check the current
URL specifications to see what is allowed as a URL.
Can someone give me a definitive link to any W3C document where I can
see this is Valid?
The relevant DTD in a the relevant HTML specification implies that it is
valid, just as href="some %¤!¤"9^ stuff I just decided to put here!" is
valid. Validity means very little in this context.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Apr 7 '07 #2
La*********@gma il.com <La*********@gm ail.comwrote:
I am little surprised about the following:
<a href="#" ...
Yes, this is often found in the web. In general this doesn't make any
sense but because the author of the web page doesn't know very much
about JavaScript and event handlers (especially about the return value
of the "onclick" handler), he uses this empty fragment identifier to
workaround some side effects of his bad and buggy JavaScript code.

Usually you'll find these empty fragment identifier together with an
onclick handler like in the following code:

<a href="#" onclick="someJa vaScriptCode()" >click here</a>

In this case clicking the link will execute the javascript code of the
onclick handler first. The hanlder can then return a value (true, false)
to tell the browser if the default action of the link must be also
executed (which means opening the page that is referenced through the
href attribute). So returning the value "false" forces the browser not
to open the link. But web authors who don't know about this don't return
any value in the event handler and so the browser is also executing the
default action for the link. Which means opening the page that is given
in the href attribute. And so these web authors tend to use this
"#" in the href attribute to prevent that the browser doesn't open a new
page. But this has also some negative side effects: some browsers scroll
the page to the top, assuming the empty fragment identifier identifies
the top of the document.
I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,
No, the href attribute must always contain an URI value. The fragment
identifier (the part after the "#") is also part of an URI value. So
"#" is a relative URL which can be resolved to the absolute URL of the
document itself. This is the reason why this "#" is "working": it
tells the browser to load the page which is already displayed and this
will usually be interpreted by the browser to do nothing (because the
page is already shown). But as I said above, some browsers scroll to the
top, some may even reload the page that is currently displayed.
--
Alexander
Apr 7 '07 #3
On 7 Apr., 14:08, "Jukka K. Korpela" <jkorp...@cs.tu t.fiwrote:
Scripsit Lastwebp...@gma il.com:
I am little surprised about the following:
<a href="#" ...

Just don't use them, mm'kay? But that's a practical issue. Formally, it is
well-defined.
I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,

Wrong. The href _attribute_ value is a _URL_. You need to check the current
URL specifications to see what is allowed as a URL.
Can someone give me a definitive link to any W3C document where I can
see this is Valid?

The relevant DTD in a the relevant HTML specification implies that it is
valid, just as href="some %¤!¤"9^ stuff I just decided to put here!" is
valid. Validity means very little in this context.

--
Jukka K. Korpela ("Yucca")http://www.cs.tut.fi/~jkorpela/
Thanks, I searched at the wrong place in the W3C docu, now I found
http://www.w3.org/Addressing/URL/4_2_Fragments.html and some other
places.
In my opinon there is still something wrong in the anchor definition
for XHTML, but ok.

Peter

Apr 7 '07 #4
On 7 Apr., 15:18, acla...@hrzpub. tu-darmstadt.de (Alexander Clauss)
wrote:
Lastwebp...@gma il.com <Lastwebp...@gm ail.comwrote:
I am little surprised about the following:
<a href="#" ...

Yes, this is often found in the web. In general this doesn't make any
sense but because the author of the web page doesn't know very much
about JavaScript and event handlers (especially about the return value
of the "onclick" handler), he uses this empty fragment identifier to
workaround some side effects of his bad and buggy JavaScript code.

Usually you'll find these empty fragment identifier together with an
onclick handler like in the following code:

<a href="#" onclick="someJa vaScriptCode()" >click here</a>

In this case clicking the link will execute the javascript code of the
onclick handler first. The hanlder can then return a value (true, false)
to tell the browser if the default action of the link must be also
executed (which means opening the page that is referenced through the
href attribute). So returning the value "false" forces the browser not
to open the link. But web authors who don't know about this don't return
any value in the event handler and so the browser is also executing the
default action for the link. Which means opening the page that is given
in the href attribute. And so these web authors tend to use this
"#" in the href attribute to prevent that the browser doesn't open a new
page. But this has also some negative side effects: some browsers scroll
the page to the top, assuming the empty fragment identifier identifies
the top of the document.
I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,

No, the href attribute must always contain an URI value. The fragment
identifier (the part after the "#") is also part of an URI value. So
"#" is a relative URL which can be resolved to the absolute URL of the
document itself. This is the reason why this "#" is "working": it
tells the browser to load the page which is already displayed and this
will usually be interpreted by the browser to do nothing (because the
page is already shown). But as I said above, some browsers scroll to the
top, some may even reload the page that is currently displayed.

--
Alexander
Found it now, thanks, see answer above.

Peter

Apr 7 '07 #5
Scripsit La*********@gma il.com:
Thanks, I searched at the wrong place in the W3C docu, now I found
http://www.w3.org/Addressing/URL/4_2_Fragments.html and some other
places.
The W3C pages are not the authoritative source on URL syntax. They refer to
URL RFCs. The authoritative specification of generic URL syntax is Internet
standard 66, currently RFC 3986, see
http://www.apps.ietf.org/rfc/rfc3986.html
In my opinon there is still something wrong in the anchor definition
for XHTML, but ok.
As I mentioned, href="#" is practically wrong anyway, so why bother? The
HTML vs. XHTML distinction is irrelevant here.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
Quote this sig to join the Clueless Club!

Apr 7 '07 #6
Scripsit Alexander Clauss:
So "#" is a relative URL which can be resolved to the absolute URL of the
document itself. This is the reason why this "#" is "working": it
tells the browser to load the page which is already displayed and this
will usually be interpreted by the browser to do nothing (because the
page is already shown).
Browsers are, by the specification, not expected to _reload_ the page, but
that's different from not doing anything. A simple href="#foo" should not
cause a reload either, but it should and it does cause a repositioning of
the document's content in the browser window.
But as I said above, some browsers scroll to
the top, some may even reload the page that is currently displayed.
All browsers I've tested treat href="#" as a reference to the top of the
page, positioning the content accordingly, without reloading the page. Some
versions of Opera have been reported to fail to understand href="#" at all,
but this should be considered a browser bug.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Apr 7 '07 #7
Jukka K. Korpela <jk******@cs.tu t.fiwrote:
A simple href="#foo" should not cause a reload either,
but it should and it does cause a repositioning of
the document's content in the browser window.
Yes, because this URL includes an explicit destination inside the
document.
All browsers I've tested treat href="#" as a reference to the
top of the page,
You've not tested all existing browsers ;-)
And of course a browser is not required to assume that a non-existing
or empty fragment identifier represents the top of the document.

But in any case, if the onclick handler would return a suitable value
the silly "#" URLs would not be necessary.
--
Alexander
Apr 7 '07 #8
Gazing into my crystal ball I observed ac*****@hrzpub. tu-darmstadt.de
(Alexander Clauss) writing in news:1hw7gek.5i zlpu1jzf1f4N%
ac*****@hrzpub. tu-darmstadt.de:
>I am little surprised about the following:
<a href="#" ...

Yes, this is often found in the web. In general this doesn't make any
sense but because the author of the web page doesn't know very much
about JavaScript and event handlers (especially about the return value
of the "onclick" handler), he uses this empty fragment identifier to
workaround some side effects of his bad and buggy JavaScript code.

I actually use it when I am in the process of creating/testing a site.
For example:
<li><a href="#">Contac t</a></li>
<li><a href="#">Links</a></li>
....
--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

Apr 7 '07 #9
In our last episode,
<11************ **********@y80g 2000hsf.googleg roups.com>,
the lovely and talented La*********@gma il.com
broadcast on comp.infosystem s.www.authoring.html:
Hello,
I am little surprised about the following:
<a href="#" ...
In the first place, you have not given enough to tell whether
the anchor is empty or not. Your question seems to be about the
href attribute. <a href="anycrap"> </awould be an empty anchor.
<a href="!@#$#%^&" >Something</awould not be an empty anchor.
I found some lines about the href tag for a site should point to an
name or in XHTML to an ID,
but in both cases this seems to be not valid name="#" or id=""...
And I wonder why the online validator allow this in all cases.DOCUMENT
types.
The specs (for 4.01) say href should be a URI, which is CDATA and in
particular an absolute URI or a relative URI either of which may be followed
by a fragment starting with "#". The fragment is supposed to be "additional
reference information to be interpreted by the user agent." The empty string
is a valid relative URI and what to make of the empty fragment is a task for
the user agent. So, yes, this seems to be VALID, but valid does not
necessarily mean useful, meaningful, what you had in mind, good, right,
desirable, etc. However id="" is not valid because id must begin with a
letter, which the empty string doesn't (4.01 spec) --- and of course,
name="#" is not valid for a similar reason.
Can someone give me a definitive link to any W3C document where I can
see this is Valid? I found only some sites where the consequence would
be this is not valid.
RFC2396 and the 4.01 spec.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 653 days to go.
Chinese Terrorists:: Xuzhou Anying Biologic Technology Development Company Ltd.
Identified :: Wangdian Industrial Zone, Peixian, CN-32, China 221623
Apr 7 '07 #10

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

Similar topics

4
26432
by: Matthias Hildebrand | last post by:
Hello, std::map< int, MyClass*> mymap; it = mymap.find( somekey ) // here happen bad things if( it != mymap.end() ) { // do something useful with it->second } else
13
3405
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
18
2477
by: Neal | last post by:
According to the specs (http://www.w3.org/TR/html401/struct/links.html#h-12.2), the <a> element requires an end tag. And so, when we use <A NAME="foo"> in HTML 2.0 to 4.01, it won't validate, it'll want to find the </A> tag. However, when I write a document containing, say, <a name="foo" /> it validates in XHTML 1.0. I'm obviously missing something here, as this confuses me somewhat. Does the magical / make the empty a element valid?...
2
1626
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the searched words are inside <a href> tags, the links are lost after putting my anchors. For example: <a class="Programa" href="#" OnClick="window.open('/something.tif');"
1
2034
by: mlv2312 | last post by:
Hi, I have experienced problems when dealing with nested anchors. I implemented some code to perform highlighting and specific anchors are used for the searched words. The problem is when the searched words are inside <a href> tags, the links are lost after putting my anchors. For example: <a class="Programa" href="#" OnClick="window.open('/something.tif');"
3
6358
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the XmlDocument was also done in a jiffy. The final step is to save the document to disk and then ship it to another system using ftp. The xml orderfile produced must fit a set specification of the recieving system. That specification states that empty elements...
3
16563
by: windandwaves | last post by:
does it matter if I write var anchors = document.getElementsByTagName("A"); or var anchors = document.getElementsByTagName("a"); Or is there a better way to catch both <a hrefs and <A HREFS
3
2108
by: August Karlstrom | last post by:
Hi everyone, In XHTML, can any empty element <foo></foobe replaced by <foo />? Example: <table> <tr><td>1</td><td>2</td></tr> <tr><td /><td>4</td></tr> </table>
3
1949
by: harv3yb1rdman | last post by:
Hi, I have a blog which people often include a link in their comment. Can anyone point me to a script or demonstrate how I can automatically surround the text links with an anchor when the page is rendered? As an example, here is a typical comment: Hi! Great pics - have you seen this one? http://warehouse.carlh.com/comic/comic_062.php
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.