2013-10-17 57 views
2

我無法找到真正我的問題相匹配的職位,所以在這裏我們去:如何用JavaScript創建一個電子郵件按鈕

我想實現按鈕「通過郵件共享」到我的網站,所以當你點擊按鈕讓我們說Outlook或雷鳥打開,並給你選擇分享一個新的郵件內的網站鏈接。

我不太確定,但我認爲我不能完全用html做,因爲facebook鏈接到他們的共享網站時也會運行JS。

+0

https://developer.mozilla.org/nl/docs/Web-based_protocol_handlers [Automically打開默認的電子郵件客戶端和預填充內容](HTTP的 – rene

+0

可能重複: //stackoverflow.com/questions/13231125/automically-open-default-email-client-and-pre-populate-content) –

回答

5

您不需要此JavaScript。只是一個簡單的HTML

<a id="emailMe" href="mailto:[email protected]">e-mail me</a> 

您還可以定義一個主題但你必須記住,你只能使用字符-Z和數字0-9。其他字符必須經過網址編碼,例如主題:「這是一個主題」應該像這樣編碼

<a id="emailMe" href="mailto:[email protected]?subject=This%20is%20a%20subject">e-mail me</a> 

如果你不想每個是很明顯的字符編碼手動,來了最後的javascript:

var subject = "This is a subject"; 
var subjectEncoded = encodeURIComponent(subject); 
document.getElementById('emailMe').href = "mailto:[email protected]?subject=" + subjectEncoded; 
5

在這裏你去:

<a href="mailto:[email protected]?subject=just-a-subject">Send a mail</a> 

希望它有幫助。

1
<a href="mailto:?Subject=SubjectHere&body=ThisIsTheMailtext"> 

爲什麼要使用JavaScript?現在它打開,你必須把收件人放在/空)。與JS

1

電子郵件鏈接

var mydiv = document.getElementById("myDiv"); 
var aTag = document.createElement('a'); 
aTag.setAttribute('href',"mailto:[email protected]?subject=Subject&body=message%20goes%20here"); 
aTag.innerHTML = "share via mail"; 
mydiv.appendChild(aTag); 
相關問題