使用Javascript,您可以在UTF-8頁面上使用encodeURIComponent()對utf-8-percent-encode編碼主體和主體hfvalue。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script>
function SendLinkByMail(href) {
var subject= "Interesting Information";
var body = "I thought you might find this information interesting:\r\n\r\n<";
body += window.location.href;
body += ">";
var uri = "mailto:?subject=";
uri += encodeURIComponent(subject);
uri += "&body=";
uri += encodeURIComponent(body);
window.open(uri);
}
</script>
</head>
<body>
<p><a href="javascript:(function()%7BSendLinkByMail()%3B%7D)()%3B">Email link to this page</a></p>
</body>
</html>
如果你在做這個服務器端,你可以建立mailto鏈接併發送它作爲href屬性值。然後,你根本不需要JS。
我假設ASP有一些像encodeURIComponent()一樣工作的URI編碼函數。
您還可以查看我的mailto URI composer頁面的源代碼作爲另一個例子。
你的也看看http://shadow2531.com/opera/testcases/mailto/mailto_uri_scheme_idea.html#send_link_by_mail和我mailto URI syntax validator。
對於我在上面的JS代碼中包含URI的<和>,請參閱RFC3986中的「附錄C.在上下文中定界URI」。
此外,而不是window.location.href,可以使用window.location的或document.location.href或document.location。我通常使用「document.location」。
爲什麼你使用JavaScript URI而不是onclick屬性,請參閱this answer。
另請注意,在上述代碼中的JS URI中,我將代碼封裝在一個匿名函數中。在這種情況下這不是必需的,因爲該函數不會返回任何會在單擊時更改文檔的內容。但是,這只是爲了好的措施而始終做到這一點。
見我Javascript URI compose,以幫助創建的JavaScript的URI。
Javascript可以爲你做這個。通過使用「document.location.href」。或者,如果您使用.php,則可以更輕鬆地完成。你可以使用PHP?讓我知道,我可以爲你做一個例子! –
不,我使用Asp;) 但是我怎麼能在那部分寫javascript?(body =「...「) –