![]() |
BASE HREF and A HREF="#" onclick="..."
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</A> method 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 |
Re: BASE HREF and A HREF="#" onclick="..."
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</A> method 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. |
Re: BASE HREF and A HREF="#" onclick="..."
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</A> method 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. |
| All times are GMT. The time now is 11:53 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.