Link to Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis M. Marks

    Link to Function

    I have seen partial answers to the following question but I am not sure
    of the best approach. I have a page that will only work with
    javascript. The link to the page indicates that.

    Within the page I have a clickable link to a function. The best html
    for that process seems to be:
    <a href="xxx" onclick="TheFun ction(); return false">CLICK HERE</a>

    I assume the "return false" causes the href to be ignored but the
    function will be called. Since the page is only accessed with
    javascript there is no need for a url. Is there some kind of dummy
    entry that can be used in place of xxx or is that ok? It seems
    unnecessary to create a page that will never be accesssed.

    Is this the only way to link to a function from a link?

    --
    Dennis M. Marks


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • Thomas 'PointedEars' Lahn

    #2
    Re: Link to Function

    Dennis M. Marks wrote:
    [color=blue]
    > I have seen partial answers to the following question but I am not sure
    > of the best approach. I have a page that will only work with
    > javascript. The link to the page indicates that.
    >
    > Within the page I have a clickable link to a function. The best html
    > for that process seems to be:
    > <a href="xxx" onclick="TheFun ction(); return false">CLICK HERE</a>
    >
    > I assume the "return false" causes the href to be ignored but the
    > function will be called.[/color]

    Correct. The `return false' cancels the `click' event, so the
    element is no longer considered interactive in this way after
    the script engine has finished processing the expressions.
    [color=blue]
    > Since the page is only accessed with javascript[/color]

    How can you be sure?
    [color=blue]
    > there is no need for a url.[/color]

    Well, there is, otherwise it is not a hyperlink and you
    should use another control. Why not input[type="button"]?
    [color=blue]
    > Is there some kind of dummy entry that can be used in place of
    > xxx[/color]

    You could use `#' but you will append to the history of the user
    that accidentally gets there without having client-side JavaScript
    support (enabled).
    [color=blue]
    > or is that ok?[/color]

    OK would be a hyperlink to a document that explains why the feature
    requires client-side scripting if it is not supported.
    [color=blue]
    > It seems unnecessary to create a page that will never be accesssed.[/color]

    Well, that depends.
    [color=blue]
    > Is this the only way to link to a function from a link?[/color]

    It is not, but it is the best one. Read the FAQ.


    PointedEars

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Link to Function

      "Dennis M. Marks" <denmarks@dcsi. net> writes:
      [color=blue]
      > Within the page I have a clickable link to a function. The best html
      > for that process seems to be:
      > <a href="xxx" onclick="TheFun ction(); return false">CLICK HERE</a>
      >
      > I assume the "return false" causes the href to be ignored but the
      > function will be called. Since the page is only accessed with
      > javascript there is no need for a url. Is there some kind of dummy
      > entry that can be used in place of xxx or is that ok?[/color]

      A link, as made with <a href="..."> is meant to link to another
      page or resource. If you don't link to one, you shouldn't use
      a link. If you just want something to push, use a button, that's
      what they are made for:
      <input type="button" value="CLICK HERE" onclick="TheFun ction()">

      If you insist on using a link, the most harmless href you can use
      is
      href=""
      The empty string is a valid URL fragment, and it should refer
      to the page itself. Older browser might get confuzed, though.
      [color=blue]
      > It seems unnecessary to create a page that will never be accesssed.[/color]

      The don't make a link.
      [color=blue]
      > Is this the only way to link to a function from a link?[/color]

      If you insist on using a link, it is the best way. If anybody mentions
      "javascript:The Function()" then ignore it. The "javascript :" URL scheme
      should generally be avoided in web pages, as there are always better
      ways to achieve what you need.
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...