Javascript mailto,从特定行的表中传递值

时间:2017-08-17 01:49:23

标签: javascript mailto

我有一个显示JSON数据的工作引导表,我在最后一列上有一些带有自定义javascrip函数的glyphicon。我可以成功获取javscript函数来执行mailto打开客户端本地邮件客户端发送电子邮件但是我希望能够传递在mailto函数中选择的行的值(主题字段和正文)。

使用mailto功能

<script>

        function EmailSME() {

        var email = '<"insert SME email Address">';
        var subject ='Sample text here';
        var emailBody = 'Hi Sample,';

        document.location = "mailto:"+email+"subject="+subject+"&body="+emailBody;
      }

    </script>

当gylficon点击表格中的列

时使用的Java脚本函数
 <script type="text/javascript">
                    function actionFormatter(value, row, index)
                    {
                        return [                        
                            '<a class="edit ml10" href="javascript:void(0)" title="Edit">',
                            '<i class="glyphicon glyphicon-edit"></i>',
                            '</a>',
                            ' ',
                            '<a class="notifications ml10" href="javascript:void(0)" title="Notifications">',
                            '<i class="glyphicon glyphicon-send"></i>',
                            '</a>',
                            ' ',
                            '<a class="email ml10" href="javascript:void(0)" title="Email">',
                            '<i class="glyphicon glyphicon-envelope"></i>'

                        ].join('');
                    }
    window.actionEvents = {
'click .email': function (e, value, row, index) {
                        $('.modalClick4').trigger('click');
                        console.log(value, row, index);

                // mailto code needs to go in here and passing the value of the specific row in the subject email       

                    }
                }

我知道所选行的值按照console.log工作我可以确认值正在传递。

需要注意的是,当我点击glyphicon&#34; email&#34;它触发一个模态,然后我有3个按钮。第一个按钮是我试图在这里实现的mailto功能。

模态按钮

<button onclick="EmailSME()" class="btn">  <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span>
            Email SME Template</button>

2 个答案:

答案 0 :(得分:0)

我相信您错过了?作业中的document.location

尝试将第一个脚本块更改为:

<script>

  function EmailSME() {

    var email = '<"insert SME email Address">';
    var subject ='Sample text here';
    var emailBody = 'Hi Sample,';

    document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody;
  }

</script>

答案 1 :(得分:0)

你错过了?。 而且你必须使用encodeURIComponent()函数。

<script>

  function EmailSME() {

    var email = '<"insert SME email Address">';
    var subject ='Sample text here';
    var emailBody = 'Hi Sample,';

    document.location = "mailto:"+encodeURIComponent(email)+"?subject="+encodeURIComponent(subject)+"&body="+encodeURIComponent(emailBody);
  }

</script>