Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mailto using javascript

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 = "[email protected]"       var mailto_link = 'mailto:' + email       window = window.open(mailto_link, 'emailWindow')       if (window && window.open && !window.closed)                    window.close() 
like image 588
Sathish Avatar asked Apr 16 '12 10:04

Sathish


People also ask

How do you use mailto in JavaScript?

Use the code below and add mailto functionality to any element using JavaScript. Copy var email = document. createElement("a"); email. href = "mailto:[email protected]"; email.

Can JavaScript be used in emails?

Can I send emails with JS or not? You can't send emails using JavaScript code alone due to lack of support for server sockets. For this, you need a server-side language that talks to the SMTP server. You can use JS in conjunction with a server script that will send emails from the browser based on your requests.


1 Answers

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:[email protected]"; } <body onload="javascript: redirect();"> 

Or just directly

<body onload="javascript: window.location.href='mailto:[email protected]';"> 
like image 101
StanE Avatar answered Sep 24 '22 09:09

StanE