Linking to javascript function

Discussion in 'JavaScript and AJAX' started by Talks_44, Sep 19, 2007.

  1. Talks_44

    Talks_44 New Member

    Joined:
    Sep 19, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    There's a few different ways people create links to javascript function, after some looking around here's what seems to be the better ways:

    CODE
    <a href="java script:{}" onclick="foo()">Call it</a>
    <a href="java script:;" onclick="foo()">Call it</a>
    <a href="java script:void(0);" onclick="foo()">Call it</a>

    <a href="#" onclick="foo(); return false">Call it</a>


    And many people will say to back it up with a server-side page or needs-JS page like:

    CODE
    <a href="jsrequired.html" onclick="foo(); return false">Call it</a>
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    onClick is the most popular way to link to JavaScript calls, people sometimes link this way too..

    HTML:
    <a href='javascript:myFunc();'>Call myFunc</a>
    
     
  3. Talks_44

    Talks_44 New Member

    Joined:
    Sep 19, 2007
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0

    Gratz for completing me!!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice