正在尝试将标题标记添加到mailto链接,正文中包含URL

Trying to add the title tag to a mailto link, with the URL in the body

本文关键字:链接 mailto 正文 URL 包含 添加 标题      更新时间:2023-09-26

我正在为我们的产品创建一个帮助网站。它将由我们的客户服务小组在网络上部署(针对登录的客户),并将与我们的软件一起部署。我们想创建一个反馈机制,但我们不能使用服务器端脚本,因为在某些情况下,用户将在本地查看帮助网站。

我们正在研究一个长期的解决方案,但目前我们正在尝试使用一个简单的<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用于将当前url添加到电子邮件正文,位于下方

 $(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>

完整代码在这里https://jsfiddle.net/50c99uan/2/