Unable to close new window after using mailto in javascript

JavaGeek

I'm trying to send invoke email when button is clicked and its working fine but extra window is getting opened during the process and i'm unable to close it even though I have tried close method. I have tried in IE 10 and IE 11 and its not working.

Below is the code

    <html>
<head>
<script type='text/javascript'>
    function sendMail(){

        var wi = window.open('mailto:[email protected]?subject=' + encodeURIComponent(document.getElementById("metric").value));
        wi.close();     
   }

</script>
</head>
<body>

<h4>Send e-mail to committee with below subject:</h4>

<form action="javascript:sendMail()" method="post" enctype="text/plain">

<select id="metric">

  <option value="test1">test1</option>
  <option value="test2">test2</option>
</select>
<br><br>

<input type="submit" value="Send">

<p></p>
</form>
</body>
</html>
Tim Consolazio

I'm going to go ahead and say this isn't how you'd go about it.

A mailto: link opens the user's default email client. If you remove the attempt to close the window in your script, you'll see this happen. But to do anything useful, you'd have to fill out the mail along with sender etc.

So the user will need to trigger the actual send in their email client.

What you would typically do is send the request to the server, and have the server use the SMTP service (pretty much all of them have it now) to put together and send the email out. It's simple to do, how exactly it works depends on what server you are going to be hosting your solution on.

To my knowledge there is no pure javascript/server-less way to do this. If you think about it, this makes sense; what would prevent somebody from putting a script in a webpage that sends out a thousand emails based on something you collected from the webpage?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript mailto using window open

From Dev

HTML "mailto:" not opening in new window

From Dev

Mailto using Javascript?

From Dev

Cannot close dialog window using Javascript in Crm

From Dev

How to close a popup window using Javascript

From Dev

Unable to close current window

From Dev

mailto: new window but 'To' field address is mailto:[email protected]

From Dev

How to automatically close the new popup window in Javascript and PHP?

From Dev

CakePHP not redirecting after opening new window with JavaScript

From Dev

Close a window with JavaScript onClick

From Dev

Close a window with JavaScript onClick

From Dev

Javascript dialog window close

From Dev

Open image in a new window using Razor and javascript

From Dev

How to enlarge an image in a new window using Javascript

From Dev

Error opening a new browser window using javascript

From Dev

Atom Electron Close and Minimize window using the html button and javascript

From Dev

How to close the window of filePicker using javascript or any JS library?

From Dev

Unable to close new WPF window until all UI threads are returned even if dispatcher priority is set to background

From Dev

Based on selection, "mailto:" link changes to "mailto: variable" using javascript

From Dev

Opening a new window using javascript with information from previous window

From Dev

Close WPF window after animation

From Dev

Close Popup Window after insert

From Dev

Close Window After Submission of Form

From Dev

Unable to switch to a new window when using IE11

From Dev

Close Window after open another window?

From Dev

Unable to traverse on dom after using javascript map?

From Dev

automatically close pylint window after python code window is close in VIM

From Dev

automatically close pylint window after python code window is close in VIM

From Dev

Atom Electron - Close the window with javascript

Related Related

  1. 1

    Javascript mailto using window open

  2. 2

    HTML "mailto:" not opening in new window

  3. 3

    Mailto using Javascript?

  4. 4

    Cannot close dialog window using Javascript in Crm

  5. 5

    How to close a popup window using Javascript

  6. 6

    Unable to close current window

  7. 7

    mailto: new window but 'To' field address is mailto:[email protected]

  8. 8

    How to automatically close the new popup window in Javascript and PHP?

  9. 9

    CakePHP not redirecting after opening new window with JavaScript

  10. 10

    Close a window with JavaScript onClick

  11. 11

    Close a window with JavaScript onClick

  12. 12

    Javascript dialog window close

  13. 13

    Open image in a new window using Razor and javascript

  14. 14

    How to enlarge an image in a new window using Javascript

  15. 15

    Error opening a new browser window using javascript

  16. 16

    Atom Electron Close and Minimize window using the html button and javascript

  17. 17

    How to close the window of filePicker using javascript or any JS library?

  18. 18

    Unable to close new WPF window until all UI threads are returned even if dispatcher priority is set to background

  19. 19

    Based on selection, "mailto:" link changes to "mailto: variable" using javascript

  20. 20

    Opening a new window using javascript with information from previous window

  21. 21

    Close WPF window after animation

  22. 22

    Close Popup Window after insert

  23. 23

    Close Window After Submission of Form

  24. 24

    Unable to switch to a new window when using IE11

  25. 25

    Close Window after open another window?

  26. 26

    Unable to traverse on dom after using javascript map?

  27. 27

    automatically close pylint window after python code window is close in VIM

  28. 28

    automatically close pylint window after python code window is close in VIM

  29. 29

    Atom Electron - Close the window with javascript

HotTag

Archive