Mailto与Jquery的链接

Mik*_*ike 1 html mailto jquery

我的网站上有一个mailto链接,工作正常.但是,我想在其上执行.click()事件,以便在用户单击该链接时进行记录.我有.click事件工作并执行ajax请求,但现在mailto链接无法打开电子邮件客户端.是否可以在客户端打开之前运行jquery函数,但仍然可以打开客户端?

这是我的代码(它只是在浏览器中打开一个空白窗口)

<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>
Run Code Online (Sandbox Code Playgroud)

Dan*_*ses 5

为了使其工作,您需要将async设置为false.

http://jsfiddle.net/5nwu7/3/

<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);},
                        async: false
                    });
                //You don't need this ---window.location.href= $(this).prop('href');
            });
            </script>
Run Code Online (Sandbox Code Playgroud)

这是因为某些浏览器在打开邮件客户端时会取消当前的ajax请求.您可以通过转到我发布的jsfiddle并删除异步行来测试这一点(在chrome 23.0.1271.97 m,windows 7,outlook 2007中测试.)