Search code examples
htmlmailto

Using mailto (html) opens a tab with chrome


I am working on a website to have it be able to use mailto without typing out the email in the script. here is the function

<script type= "text/javascript"> 
    function createemail(name,subject) 
      {
      var email = name + '@email.com';
      var mailto_link = 'mailto:' + email + '?subject=' + subject;
      win = window.open (mailto_link, 'emailWindow');
      //if (window && window.open && !window.closed) window.close()----DOES NOT CLOSE WINDOW };
  </script>

I then reference the function with a onclick command

   <tr>
  <td align="center" valign="middle">
    <font size="+1"><a onclick = "createemail('TEST','Subject Text')"; style= "cursor:pointer; cursor:hand; color:#0000ee"><u>Sales</u></a></font>
  </td>
</tr>

The text is changed to look like a hyperlink but it just references the function


Solution

  • I changed the Function to

      <script type= "text/javascript"> 
    function createemail(name,subject) 
      {
      var email = name + '@bldgcs.com';
      location.href = 'mailto:' + email +'?subject=' + subject;
      };
    

    The location.href seemed to fix the problem