SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Who Me? JeremyL's Avatar
    Join Date
    Dec 1999
    Location
    Dallas, TX
    Posts
    296
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 JS commands attached to one href tag?

    Quick question. Is this legal and will it work properly with both JS commands in the same href tag?

    Code:
    <a href="#" target="_blank" onMouseDown="return gotoclick(this, 'P1')" onClick="javascript:urchinTracker('/outgoing/shopping');">
       Anchor Text
    </a>
    I can tell from testing the link js still works. Just want to make sure there wont be any mix ups with the Google tracking code also.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, it should work without any problems. onmouseup is probably a better idea to use than onmousedown. You could also do this, which is the best way:
    HTML Code:
    <a href="#" onclick="urchinTracker('/outgoing/shopping'); return gotoclick(this, 'P1');">Anchor Text</a>
    I removed the "target" attribute because opening new windows is a horrible idea. If the user wants to open something in another window, let them decide to do it.

    And "href" is not a tag. It is an attribute. onclick and onmousedown are attributes as well (and it's good practice to keep them in lowercase).

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Are you sure you want to reload the current page if javaScript is disabled? It would be better if you either link to a different page in that case or use a <span> in place of the <a> if you don't want to link anywhere in that case.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •