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

Discussion in 'Javascript' started by Vincent van Beveren, Jul 6, 2006.

  1. 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
    Vincent van Beveren, Jul 6, 2006
    #1
    1. Advertising

  2. Vincent van Beveren

    Robert Guest

    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.
    Robert, Jul 6, 2006
    #2
    1. Advertising

  3. 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.
    Vincent van Beveren, Jul 6, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beto

    href onclick and eval problem

    Beto, Jan 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    579
  2. CRON
    Replies:
    24
    Views:
    200,275
    Adrienne Boswell
    Jun 20, 2006
  3. Chuck

    onclick for button and window.location.href

    Chuck, Feb 2, 2010, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    6,328
    Chuck
    Feb 2, 2010
  4. Jez

    onClick and href="#"

    Jez, Jul 17, 2003, in forum: Javascript
    Replies:
    6
    Views:
    109
  5. Replies:
    2
    Views:
    432
Loading...

Share This Page