Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   BASE HREF and A HREF="#" onclick="..." (http://www.velocityreviews.com/forums/t925659-base-href-and-a-href-onclick.html)

Vincent van Beveren 07-06-2006 07:50 AM

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

Robert 07-06-2006 08:12 AM

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.

Vincent van Beveren 07-06-2006 08:33 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57