-1

I have a simple html that will pop out a new email message for people to send out email. I need to close a window after the email message popped out. I wish to keep only the email message box.

This is my code, but it's not working:

<html>
       <head>
       <script type="text/javascript">
        function mymessage()
        {
         location.href = "mailto:abc@com.sg?subject=EmailToEnter";
        }
        </script>
    </head>
    <body onload="mymessage()">
        <script type='text/javascript'>
        settimeout('self.close()',1000);
        </script>
    </body>
</html>
Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
JOHN LEE
  • 11
  • 1
  • 1
  • 2
  • 2
    tried `window.setTimeout()`? - case sensitive, if i write settimeout it never works – UnskilledFreak Nov 28 '14 at 10:28
  • Do you open window to send e-mail in the same window where javascript place? If it is, your script never been working. – CnapoB Nov 28 '14 at 10:35
  • You have more details here but this is a hack and it will be difficult for you to make it work cross browser. http://stackoverflow.com/questions/57854/how-can-i-close-a-browser-window-without-receiving-the-do-you-want-to-close-thi Closing the browser page on somebody is like throwing a customer out of your store with a kick in the ... Are you sure you need to do it? – mihaisimi Nov 28 '14 at 10:32

2 Answers2

0

Try something like this:

function mymessage()
{
    var d=document.createElement('A');
    d.target='_blank';
    d.href='mailto:abc@com.sg?subject=EmailToEnter';
    d.click();
}

function closewindow()
{
    var d=document.createElement('A');
    d.href="javascript:window.open('', '_self', '').close()";
    d.click();
}

Or you can use window.open

Also use construction like this

window.setTimeout(function(){closewindow();},1000);
CnapoB
  • 665
  • 1
  • 9
  • 16
0

Use this

setTimeout("window.close()", 1000);

BUT

This method is only allowed to be called for windows that were opened by a script using the window.open() method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

https://developer.mozilla.org/en-US/docs/Web/API/Window.close