mailto using javascript
html, javascript, mailto
Solution
No need for jQuery. And it isn't necessary to open a new window. Protocols which doesn't return HTTP data to the browser (`mailto:`, `irc://`, `magnet:`, `ftp://` (<- it depends how it is implemented, normally the browser has an FTP client built in)) can be queried in the same window without losing the current content. In your case:
function redirect()
{
window.location.href = "mailto:mail@example.org";
}
<body onload="javascript: redirect();">
Or just directly
<body onload="javascript: window.location.href='mailto:mail@example.org';">
Problem
I want to open a new outlook mail template with the 'To address' whenever a user clicks an image. I have return my code in a html page(linked with the image), whenever it loads the javascript should open a new mail template. But the functionality is not working. Kindly let me know what is wrong in my code. ``` body onLoad="redirect()" script language="JavaScript" function redirect() var email = "xyz@something.com" var mailto_link = 'mailto:' + email window = window.open(mailto_link, 'emailWindow') if (window && window.open && !window.closed) window.close() ```