【发布时间】:2015-02-23 12:33:20
【问题描述】:
我有一个 javascript 在新窗口中打开邮件客户端以发送电子邮件:
<a onClick="javascript:window.open('mailto:user@test.com', 'Mail');event.preventDefault()" href="mailto:user@test.com">Send a e-mail</a>
但问题是,当 Yahoo / Gmail 客户端撰写页面时,“To”字段默认设置为“mailto:user@test.com”这实际上应该是“user@test.com”
我们怎样才能做到这一点 - 我只需要在新页面上打开电子邮件客户端
HTML 代码 - 请注意它会打开一个 iframe 窗口作为目标:
<!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>
【问题讨论】:
-
OT:
onclick属性中不需要javascript:。仅当您将 JS 放入通常包含 URL 的属性中时才需要这样做。 -
你为什么使用javascript?只需使用 href 属性中的 mailto 即可获得相同的行为。
-
它不会打开新页面 - 它使用默认页面使用户从应用程序中移出
-
所以只需添加 target="_blank" 属性。查看@dr_dev 答案。
-
Firebug 显示我按顺序打开以下 URL:compose.mail.yahoo.com/?To=mailto%3Auser%40test.com 然后in-mg61.mail.yahoo.com/neo/…
标签: javascript jquery