Search code examples
jqueryhtmlmailto

Mailto link with Jquery


I have a mailto link on my site that is working fine. However, I want to perform a .click() event on it to log when the user clicks that link. I have the .click event working and performing the ajax request, but now the mailto link doesn't open the email client. Is it possible to run a jquery function before the client opens, but still make the client open?

here is the code I have (it just opens a blank window in the browser)

<script type='text/javascript'>
                    jQuery('span.email a').on('click',function (){
                        jQuery.ajax({
                            type: 'POST',
                            url: '', //url here
                            data: {comment: 'Email Sent', category : 'EE', store_id: '" . $this->store_id . "'},
                            success: function (data){jQuery('#alerts').html(data);}
                        });
                    window.location.href= $(this).prop('href');
                });
                </script>

Solution

  • You don't need the window.location.href= $(this).prop('href');. If you just let the click continue on as normal, it should do what you want.