[英]Trying to add the title tag to a mailto link, with the URL in the body
我正在為我們的產品創建一個幫助站點。 它將由我們的客戶服務小組在網絡上部署(適用於已登錄的客戶),並將與我們的軟件一起部署。 我們想創建一個反饋機制,但是我們不能使用服務器端腳本,因為在某些情況下,用戶將在本地查看幫助站點。
我們正在研究一個長期的解決方案,但是現在我們正在嘗試通過一個簡單的<a href="mailto">
鏈接(我們將其格式化為一個按鈕)來做到這一點:
<p class="docfeedback"><a href="mailto:example@example.com?subject=Documentation Feedback" title="We welcome your feedback on this documentation. If you cannot send mail from this server, please send your feedback to: example@example.com>
我想要的是獲取<title>
元素的值並將其放在Subject中,我想在正文行中獲取url路徑名(僅路徑名)。
我已經閱讀了一些答案,這些答案為我提供了部分解決方案,但我希望將它們放在一起,並以正確的方式進行編碼。
我一直在閱讀有關使用javascript獲取URL的信息 ,我可以在消息正文中成功完成此操作。 但是,然后我嘗試使用此答案將主題中的第一個H1作為消息的主題。 然后,我將其更改為title
元素。 (我的項目可以自動訪問jquery [1.8.3],因此不必專門調用它。)
因此,這可行,但是我不確定如何將它們放在一起。 這是我的HTML中的當前代碼。
<script>
$(document).ready(function(){
var mailtoHref = $('#mailme a').attr('href'); //get href
var h1Text = $('title').text(); //get h1 text
$('#mailme a').attr('href', mailtoHref + h1Text ); //append it to mailto://
});
</script>
<div id="mailme">
<p class="docfeedback">
<a href="mailto:example@example.com?subject=Documentation Feedback for topic: " title="We welcome your feedback on this documentation. If you cannot send mail from this server, please send your feedback to: example@example.com">Send us documentation feedback</a>
</p>
</div>
p.docfeedback /* only used on master page for feedback link */ { text-align: center; font: bold 11px Arial; text-decoration: none !important; background-color: #EEEEEE; padding: 5px 9px 5px 9px; border: 1px solid #CCCCCC; border-radius: 10px; width: 225px; } p.docfeedback a:link, p.docfeedback a:visited, p.docfeedback a:hover, p.docfeedback a:active { color: #666; text-decoration: none !important; }
<head> <title>This is the name of the document</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> </head> <script>/* <![CDATA[ */ $(document).ready(function(){ var mailtoHref = $('#mailme a').attr('href'); //get href var h1Text = $('title').text(); //get h1 text $('#mailme a').attr('href', mailtoHref + h1Text ); //append it to mailto:// }); /* ]]> */</script> <div id="mailme"> <p class="docfeedback"><a href="mailto:example@example.com?subject=Documentation Feedback for topic: " title="We welcome your feedback on this documentation. If you cannot send mail from this server, please send your feedback to: example@example.com">Send us documentation feedback</a> </p> </div>
您能提供的任何幫助,我將不勝感激。
下面是用於向電子郵件正文添加當前網址的jQuery
$(document).ready(function() {
var url = window.location.href; //get url
var h1Text = $('title').text(); //get h1 text
var email = 'example@example.com';
var body = url;
var subject = 'Documentation Feedback for topic: '+h1Text;
var hrefTitle = 'We welcome your feedback on this documentation. If you cannot send mail from this server, please send your feedback to: '+email;
$('#mailto').attr('href','mailto:'+email+'?body='+body+'&subject='+subject);
$('#mailto').attr('title', hrefTitle);
});
而且html mailto鏈接現在是這樣的
<a id="mailto" href="" title="">Send us documentation feedback</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.