href="javascript:func()" vs href="#" onclick="javascript:func()"

Discussion in 'HTML' started by CRON, Jun 18, 2006.

  1. <snip>

    As the activation/execution of javascript pseudo-protocol HREFs are well
    known to directly cause numerous issues (usually perceived as problems)
    in IE browsers, and an alternative exists that can achieve the same
    without provoking those issues, there is no need to look for any other
    reason for avoiding their use.

    In practice the absence of any formal specification would be expected to
    result in inconsistent implementations, and that is what is seen. For
    example, while most implementations will react to the javascript
    expression evaluating to a non-empty string value by replacing the
    current document's contents with that string (interpreted as HTML),
    IceBrowser will not replace the document with such a string.

    Richard.
     
    Richard Cornford, Jun 19, 2006
    #21
    1. Advertisements

  2. CRON

    Jim Moe Guest

    "javascript:" is not a standard protocol. Not like "http:", "ftp:",
    ""ldap:", "mailto:" etc. See <http://www.faqs.org/rfcs/rfc3986.html>.
    It has become a common practice among browser authors to support the
    non-standard "javascript:" because some organizations (Netscape,
    Microsoft) had decided to advocate it.
    Not really. It is a construct in common use.
    It is misapplication of one type of construct (URI) to workaround the
    limitations of another (onclick=). Such is no longer the case.
     
    Jim Moe, Jun 19, 2006
    #22
    1. Advertisements

  3. Gazing into my crystal ball I observed Toby Inkster
    I hate that when that happens! Of course, I can't find the one that's
    really broken right now. I'll find it and post it tomorrow.
     
    Adrienne Boswell, Jun 19, 2006
    #23
  4. CRON

    Jim Higson Guest

    Yes, but I said "Or, if the link must be created on the server-side, try
    something like:" and then gave the unhiding example.

    Meaning, removing the hiding would be an easy way if for some reason the OP
    found it much easier to make the link on the server. I can think of a few
    reasons why this might be the case. For example, under MediaWiki media
    paths contain md5 hashes that are only easily knowable on the server side.

    I suppose you could use PHP to write a literal string value of the hash into
    the javascript, but I was just trying to keep things simple.
     
    Jim Higson, Jun 19, 2006
    #24
  5. Aha! I found one. This one doesn't work in Firefox either, only IE.
    <http://catherine/beta/files/searchr...cessories&flag=notmenu&cityid=18&cities=18,22>
    Click on Shopping Notes - FF and Opera do nothing, only IE opens a new
    window. (love that rendering engine switch in FF!).
     
    Adrienne Boswell, Jun 20, 2006
    #25
  6. CRON

    davidb

    Joined:
    May 29, 2015
    Messages:
    1
    Likes Received:
    0
    I have to do this i know its been AGES since anyone commented on the question so i will repeat it and give a html answer thats simple effective and a little question as to why people didnt think of it in the first place.


    Howdy!
    I was wondering which is better to use:

    href="javascript:func()"

    OR

    href="#" onclick="javascript:func()"

    Problem is the second one, anchors to the top of the page which is very
    messy in most cases.

    Thanks
    Ciaran ;c)

    Okay so this person is asking which is better to create a link that does nothing just clicks and unlike the href="#" onclick="javascript:func()" Well everyone was trying too much look at your basic html book and think a pure html way to create a link that doesnt do anything except click and stay in the same position is this link here
    <a name="anchor" href="#anchor">Look Ma Im calling the same link that i am in so i go nowhere</a>

    add your javascript functions or whatever with onclick and your link does whatever you want without going to anywhere but the same page at the same spot

    <a name="anchor" href="#anchor" onclick="">Non functional link goes here and thats it</a>
     
    davidb, May 29, 2015
    #26
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.