繁体   English   中英

尝试将标题标签添加到mailto链接中,并在正文中添加URL

[英]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>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM