How to execute a script after a link is clicked, when browser does not support JavaScript?

后端 未结 3 1654
清酒与你
清酒与你 2021-01-28 04:18

I am trying to use Facebook conversion code like below that includes
both scripts and noscripts tags:


    
      

        
3条回答
  •  情书的邮戳
    2021-01-28 04:36

    Have you tried using the JavaScript onclick event? For example:

    var el; // This is your element pointing to the link you want to handle
    el.onclick = function() {
        // Execute your code here, this event is fired before the default behaviour is executed which is to lead the user to the URL
    };
    

    If your el has an ID of mylink, then you can simply assign el as

    var el = document.getElementById('mylink');
    

    This code becomes even simpler to handle if you're using a JS library like jQuery but for the moment I'm assuming you're not.

提交回复
热议问题