SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Onclick events

  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    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:

    onclick=javascript:wtslog('al2243590','3','http','Installer','event_track');
    (Web-Stats tracking)

    onclick=recordOutboundLink(this, 'Installer', 'Install'); return false;
    (Google analytics tracking)

    onclick=window.open(this.href);
    (To open link in new tab)

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

    <a href="http://www.mediafire.com/?54iqcsl" onclick="javascript:wtslog('al2243590','3','http','Instalsr-installer','event_track'); window.open(this.href); 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
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    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.

    <html>

    <head>

    <style type="text/css">
    <!--
    #posnLink { position: absolute; top:100px; left:100px; width:200px; }
    -->
    </style>
    <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;
    }
    //-->
    </script>
    </head>

    <body>

    <!-- 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
    Link</a>
    </div>
    <!-- end of div posnLink -->

    </body>

    </html>


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
  •