Search code examples
javascriptmailto

window.open(url) mailto adds a hashtag to end of my url. How do I stop it from doing that or forward my url/# to my url/?


Here is the simple function that gets called when a button is clicked:

// Contact form
function sendEmail(){
  var name = document.getElementById("nameField").value;
  var email = document.getElementById("emailField").value;
  var subject = document.getElementById("subjectField").value;
  var message = document.getElementById("messageField").value;

  if(name != "" && email != "" && subject != "" && message != ""){
    var url = 'mailto:[email protected]?subject=' + name + ' (' + email + ')' + ' ' + subject + '&body=' + message;
    window.location.href = url;
  } else {
    console.log("SOMETHING WAS EMPTY");
  }

};

But then it keeps redirecting me to http://127.0.0.1:5500/# instead of http://127.0.0.1:5500/ How do I prevent this?


Solution

  • I figured out what the issue was. I had action=“#” in the form html. I will mark this as answered.