I am trying to make pop a modal window after a user as click on 3 different links on a site. I am not too sure how to achieve it. I am using this JS script to track the click

window.onload = function() {
    var clicked = readCookie('popunder');
    if(clicked == null) {
        clicked = 0;

    if(clicked >= 3) {

    var allLinks = document.getElementsByTagName("a");
    for(i=0;i<=allLinks.length;i++) {

    function countClicks() {           
        if(clicked == 2) {
            popunder(); //something to do
        } else {
            doCookie('popunder', clicked, 1);

    function popunder() { alert('thats 3 clicks!'); }

    function doCookie(name,value,days) {
        if (days) {
            var date = new Date();
            var expires = "; expires="+date.toGMTString();
        } else {
            var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";

    function readCookie(name) {
        var readName = name + "=";
        var cSplit = document.cookie.split(';');
        for(var i=0;i < cSplit.length;i++) {
            var sc = cSplit[i];
            while (sc.charAt(0)==' ') sc = sc.substring(1,sc.length);
            if (sc.indexOf(readName) == 0) return sc.substring(readName.length,sc.length);
        return null;

I am using ctools on a site to manage modal on a particular links but i don t know how to link this action on a 3rd click, which could be any link.

  • I'm not seeing anything ctools related in your code. Can you please point out the line(s) where Ctools is giving you trouble or what errors you're seeing? – tenken Aug 21 '14 at 14:45
  • Hello Molot Thank you for your interest, and sorry for being confusing. (it is the first time i am posting something here). I am thinking to use the script i post and ctools to fired off a modal after 3 click. i read ctools doc but i get a bit lost. i simply just don't know how to integrate ctools with my script. i post the script to show what i am using. hope this is clear enought , sorry if it is not – user2876285 Aug 21 '14 at 15:12
  • Hi welcome here, my name is Tenken by the way. The only advice I can give you integrating this custom script with Drupal is to review the Javascript API for Drupal drupal.org/node/751744 and the Drupal Javascript Documentation drupal.org/node/121997 – tenken Aug 21 '14 at 17:44
  • Thanks Tenken i will look this way. i will keep updating with my progress and hopefully i will be able to share a solution. – user2876285 Aug 22 '14 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.