[Solved] how to call javascripte funiction when user click on link or using src tag of html [closed]


The link:

    <a onClick="doTheMagic('http://www.google.com/',1);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_1">0</span>; Remaining Total Clicked <span id="timesRequired_1">10</span>
    <br />
    <a onClick="doTheMagic('http://www.facebook.com/',2);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_2">0</span>; Remaining Total Clicked <span id="timesRequired_2">10</span>
    <br />
    <a onClick="doTheMagic('http://www.twitter.com/',3);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_3">0</span>; Remaining Total Clicked <span id="timesRequired_3">10</span>

The javascript:

var clickCounter = new Array();
clickCounter[1] = 0;
clickCounter[2] = 0;
clickCounter[3] = 0;

function doTheMagic(src,linkNumber){
    clickCounter[linkNumber]++;
    if(clickCounter[linkNumber] >= 10){
       poptastic(src);
    }
    document.getElementById("timesClicked_" + linkNumber).innerHTML = clickCounter[linkNumber];
    document.getElementById("timesRequired_" + linkNumber).innerHTML = (10 - clickCounter[linkNumber]);
}

var newwindow;
var adParams = {a: '9386380', size: '728x90'};
var size = adParams['size'].split("x");
function poptastic(url){
    var params = [
                'height="+size[0],
                "width="+size[1],
                "fullscreen=no' // only works in IE, but here for completeness
                ].join(',');
    newwindow=window.open(url,'name',params);
    if (window.focus) {newwindow.focus()}
}

jsfiddle

20



solved how to call javascripte funiction when user click on link or using src tag of html [closed]