문제

I have a page with an email link

<a href="mailto:email@address.com?subject=Test Story&amp;body=abc.com
">Email Link</a>

I want to check that If User clicks on this link open the default Email client, but I also want to update in Database that User has mailed. I know this is all happening at client side, Is there any way I can check either User clicked on it or not? onclick is not there for anchor tag. Any help in this regard.

도움이 되었습니까?

해결책

You need to listen for the click event on <a> tags with a "mailto:" link. Assuming you're using jQuery, here is the code:

$('a[href^="mailto:"]').on('click', function(e){
  var email = $(this).attr('href').replace('mailto:', '');
  // submit action to server here.
});

Update: make sure this code is running after the DOM ready event, like so:

jQuery(function($){
  $('a[href^="mailto:"]').on('click', function(e){
    var email = $(this).attr('href').replace('mailto:', '');
    // submit action to server here.
  });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top