Href to the current page

T

toufik toufik

I like to make a link in a web page to the page itself,
I've tried <a href=".">, but it open the directory.

Thanks for any help.
 
W

Webcastmaker

I like to make a link in a web page to the page itself,
I've tried <a href=".">, but it open the directory.

Why not just have the href point to the page?

For example in a page named mypage.html why not have <a
href="mypage.html">Mypage</a>

Not sure what you are "really" trying to do, but that will accomplish
your request.
 
D

David Dorward

toufik said:
I like to make a link in a web page to the page itself,

Whatever for? The user is already at the current page by the time they can
activate the link.
 
T

toufik toufik

Thanks friends, I need this in a function that return an html text, I use it
in many area so it will be simple If I find something like "THIS" or "ME"...
 
J

Jukka K. Korpela

Dylan Parry said:
For what purpose?

That's what I wonder too, but anyway it is technically possible to do so
in several ways. The way to do it magically, without hard-coding the
page's URL onto the page itself, is to use
href="#"
By URL specifications, "#" is a reference to the start of the current
document.
 
A

Augustus

toufik toufik said:
I like to make a link in a web page to the page itself,
I've tried <a href=".">, but it open the directory.

You could use:
<a href='#'>This Page</a>

But no guarantee that it works in every browser (I don't know if it does or
does not work in every browser... I had to do the same thing a year ago and
was using <a href='#'> and somebody said it might not work in every browser)

Best thing to do would be to use server side scripting to identify the
current page and then insert that in the HREF tag

In ASP it would be:
<a href='<%=request.serverVariables("script_name")%>'>This Page</a>

I'd presume every scripting language has something similar
 
K

Kris

Jukka K. Korpela said:
By URL specifications, "#" is a reference to the start of the current
document.

Is it? I remember in another thread very recently (sorry I cannot come
up with a ref to back that up) it was brought up that the behaviour of a
an empty fragment identifier is unspecified and hence unpredictable.
 
D

Dylan Parry

Kris said:

Like Jukka says, "specifications". As we all know, not all browsers are
written to the standards, and as such the behaviour is unpredictable.
 
S

SpaceGirl

Augustus said:
You could use:
<a href='#'>This Page</a>

But no guarantee that it works in every browser (I don't know if it does or
does not work in every browser... I had to do the same thing a year ago and
was using <a href='#'> and somebody said it might not work in every browser)

Best thing to do would be to use server side scripting to identify the
current page and then insert that in the HREF tag

In ASP it would be:
<a href='<%=request.serverVariables("script_name")%>'>This Page</a>

I'd presume every scripting language has something similar

Two people have said that, but I've yet to find a browser that people
are actually using that doesn't support it. IE, Mozilla, Netscape, Opera
- all versions, all platforms support it. Perhaps in an accessiblity
thing? Too tired to go checkin', sorry. If it's not that, then it's not
worth worrying about. # is just fine.

--


x theSpaceGirl (miranda)

# lead designer @ http://www.dhnewmedia.com #
# remove NO SPAM to email, or use form on website #
 
K

Kris


Like Jukka says, "specifications". As we all know, not all browsers are
written to the standards, and as such the behaviour is unpredictable.[/QUOTE]

No. I really recall someone drumming up a specification that says that
there has to be a (non whitespace) character after the # character.
 
J

Jukka K. Korpela

toufik toufik said:
Thanks friends, I need this in a function that return an html text, I
use it in many area so it will be simple If I find something like
"THIS" or "ME"...

This does not explain anything. There are no functions in HTML, and you
haven't told us what you are really trying to achieve. Posting the URL of
your current design is probably necessary but not sufficient for getting
a useful answer.
 
T

toufik toufik

I've tried #, it works in IExplorer.
For the moment it does the job, Thanks friends

for Jukka: It is a php function, because I generate My HTML using a php
script.

Thanks.
 
T

Toby Inkster

toufik said:
for Jukka: It is a php function, because I generate My HTML using a php
script.

Then use:
<a href="<?= $_SERVER['PHP_SELF'] ?>">current page</a>
 
B

brucie

in post: <
Is it? I remember in another thread very recently (sorry I cannot come
up with a ref to back that up) it was brought up that the behaviour of a
an empty fragment identifier is unspecified and hence unpredictable.

'#' is neither a URI nor a fragment identifier but "is used to delimit a
URI from a fragment identifier in URI references [RFC2396 2.4.3]" so the
only logical interpretation is to consider href="#" an empty URI
(href="") in which case "an empty URI reference within a document is
interpreted as a reference to the start of that document [RFC2396 4.2]"

but some UAs do nothing.
 
R

rf

Kris said:
Like Jukka says, "specifications". As we all know, not all browsers are
written to the standards, and as such the behaviour is unpredictable.

No. I really recall someone drumming up a specification that says that
there has to be a (non whitespace) character after the # character.[/QUOTE]

That was I.

<quote>
My feeling is that it is an error condition. The spec talks about what to do
with a fragment identifier that is incorrect (perhaps misspelt) but not
about one that is simply missing.

<researches>

RFC1738 talks about fragment/anchor identifier but only that it might be
there (including the #).

RFC1808 mentions fragment identifier by pointing out that "a parser must be
able to recognise the fragment when it is present".

Aha, RFC1808, in section 2.2 defines in modified BNF form
"fragment = 1*pchar"
and mentions that the 1* means "[one] or more repetitions of the [pchar].

So, zero repetitions is not allowed and href="#" is therefore an error.

Since it is an error then the browser, as per the spec, is at liberty to
interperet it as the browser sees fit. There is no "correct" behaviour.
</quote>
 
B

brucie

in post: <
rf said:
Aha, RFC1808,

RFC2606 is new and improved with only one third the fat so its healthier
for you.
So, zero repetitions is not allowed and href="#" is therefore an error.

but.. but.. but.. even if that is so a '#' and the fragment is not part
of a URI so a href="#" is an empty URI and we all know "an empty URI
reference within a document is interpreted as a reference to the start
of that document"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top