SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Onclick events

  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    0 Post(s)
    0 Thread(s)

    Onclick events

    Hi all:

    Im having this problem with multiple onclick on one link and maybe you can help me.

    I have a link on my web page that i need to track with two Stats programs, and i need this link to be openned in a new tab.

    So i need these 3 events (open i new tab and both trackers) to trigger each time a visitor clicks on that link.

    The 3 onclick i need to use are these:

    (Web-Stats tracking)

    onclick=recordOutboundLink(this, 'Installer', 'Install'); return false;
    (Google analytics tracking);
    (To open link in new tab)

    So i tought my web page link would be like this :

    <a href="" onclick="javascript:wtslog('al2243590','3','http','Instalsr-installer','event_track');; return false; recordOutboundLink(this, 'Installs', 'Installer'); return false;" >Link</a>

    But this doesnt work. I read that i have to build a function that call these 3 onclicks but since im not familiar with programming languages even i have searched a lot i dont find the appropiate syntax.

    Id need both, The function that calls the 3 onclick, and the syntax of the Link in my page itself. I tried to follow generic examples but i failed. Could you please show me how these syntaxes finally should look??

    These would be great help to me since im stucked on this.

    Thanks in advance

  2. #2
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    2 Post(s)
    0 Thread(s)
    This is the general method, but you will need to tidy up the tracker scripts. You will also need a page to open.
    It works by handling the onclick event first, then returning true so that the link carries out its default action, which is to open the href page in the target window - a blank window in this case.



    <style type="text/css">
    #posnLink { position: absolute; top:100px; left:100px; width:200px; }
    <script type="text/JavaScript">
    function trackers(linkObj)
    { //Web-Stats tracking
    // do something like
    // javascript:wtslog('al2243590','3','http','Installer','event_track';
    alert("process webstats") // info only
    // Google analytics tracking
    // do something like
    // recordOutboundLink(linkObj, 'Installer', 'Install');
    alert("process Google Analytic") // info only
    // return to allow link to finish opening page to new window (target)
    return true;


    <!-- you will also need a page to open before this will work -->
    <div id="posnLink">
    <a href="pageToOpen.html" onclick="return trackers(this)" target="_blank">Your
    <!-- end of div posnLink -->




Posting Permissions

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