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

BASE HREF and A HREF="#" onclick="..."

P: n/a
Hey everyone,

I've looked for this and I wouldn't know what the best practice would be
for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use the
<A HREF="#" onclick="...">Hello</Amethod to invoke a JavaScript.
However, because of the BASE tag, when clicking a link containing only a
# as 'href' it will load the root index.html file. What I want is it to
do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.

Both however, I've learn it isn't good practice to use javascript: in a
link. The SPAN as link would be a sort of Sim-HREF, which will probably
end up being trouble (span:hover anyone?). Anyone has a viable solution,
cause I must be missing something.

Thanks in advance,
Vincent
Jul 6 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Vincent van Beveren wrote:
Hey everyone,

I've looked for this and I wouldn't know what the best practice would be
for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use the
<A HREF="#" onclick="...">Hello</Amethod to invoke a JavaScript.
However, because of the BASE tag, when clicking a link containing only a
# as 'href' it will load the root index.html file. What I want is it to
do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.
Return false in the onclick handler.
Jul 6 '06 #2

P: n/a
Why did I not think of that...

Thanks Robert!
Vincent

Robert wrote:
Vincent van Beveren wrote:
>Hey everyone,

I've looked for this and I wouldn't know what the best practice would
be for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use
the <A HREF="#" onclick="...">Hello</Amethod to invoke a
JavaScript. However, because of the BASE tag, when clicking a link
containing only a # as 'href' it will load the root index.html file.
What I want is it to do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.

Return false in the onclick handler.
Jul 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.