0

I am having a javascript to open a mail client in a new window to send an e-mail:

<a onClick="javascript:window.open('mailto:user@test.com', 'Mail');event.preventDefault()" href="mailto:user@test.com">Send a e-mail</a>

But the issue is that when Yahoo / Gmail clients compose pages opens up the 'To' field is set to "mailto:user@test.com" by default which should actually be "user@test.com"

How can we achieve the same - I need to open the e-mail client on a new page only

HTML Code - please note that it would open an iframe window as target:

<!DOCTYPE html>
<html dir="ltr">
<head>
<style>
span {
    float: left;
    width: 0.7em;
    font-size: 400%;
    font-family: algerian, courier;
    line-height: 80%;
}
p {
    letter-spacing: 2px;
    line-height: 200%;
}
</style>
</head>
<body>
<hr align="centre" width="50%"/> 
<p align="justify">
<img src="./images/dev.jpg" align="left" width="300px height="400px" hspace="20"/>
<strong><span>A</strong></span>t a time ... </p>
<h1>Contact:</h1>
<p align="justify">
<a href="http://www.google.com" target="_blank">Google</a><br/>
Professor<br/>
<a href="mailto:user@test.com" target="_blank">Send An e-mail</a>
<a onClick="window.open('mailto:user@test.com', 'Mail');event.preventDefault();" href="mailto:user@test.com">Send a e-mail</a>
</p>
</body>
</html>
Lucky
  • 16,787
  • 19
  • 117
  • 151
Programmer
  • 8,303
  • 23
  • 78
  • 162
  • 1
    OT: you don't need `javascript:` in `onclick` attributes. That's only needed when you put JS in an attribute that normally contains a URL. – Barmar Dec 26 '14 at 05:10
  • Why are you using javascript? You can get the same behavior just using the mailto in the href attribute. – ianaya89 Dec 26 '14 at 05:13
  • Well it does not opens a new page - it uses the default page making user to move out from the application – Programmer Dec 26 '14 at 05:15
  • So just add the target="_blank" attribute. Check out @dr_dev answer. – ianaya89 Dec 26 '14 at 05:18
  • Firebug shows me opening the below URL in order: https://compose.mail.yahoo.com/?To=mailto%3Auser%40test.com then https://in-mg61.mail.yahoo.com/neo/launch?action=compose&.rand=xxxxxxx#to=mailto%3Auser%40text.com – Programmer Dec 26 '14 at 05:22
  • Well it is not opening in a new window – Programmer Dec 26 '14 at 05:23

4 Answers4

2

It's because google & yahoo expect the url to have query strings of "?to=" instead of "?mailto=" See this question for more details

Community
  • 1
  • 1
  • Thanks - I was thinking issue is with my code. Then I understand we do not have a way to rectify this as we do not know which client would user choose any way – Programmer Dec 26 '14 at 05:34
1

You have specified the url in window.open to be "mailto:user@test.com", that is the reason why it's opening that url in a new window. If your requirement is to open the mail client with the mentioned address i.e "user@test.com", you can simplty do it with the below line.

<a href="mailto:user@test.com?Subject=Mail" target="_blank">Send an e-mail</a>
dr_dev
  • 492
  • 3
  • 17
0

Please try this,in the below example no need to use javascript.

<a href="mailto:user@test.com?Subject=Mail" target="_top">Send Mail</a>

for MORE DETAILS

Priyank
  • 3,778
  • 3
  • 29
  • 48
-1

Well I'm using latest chrome version(39.*) and Both the "Send an e-mail" and "Send a e-mail" links opens a new tab page for me..

Since I have configure my browser to open mailto links to open with Gmail by default, it opens gmail page with a compose window open where the to field is set to user@test.com and not mailto:user@test.com

Fiddle

Lucky
  • 16,787
  • 19
  • 117
  • 151