简体   繁体   English

Wordpress JQuery 将变量的内容作为可点击链接发送到电子邮件正文

[英]Wordpress JQuery sending content of variable to email body as clickable link

I don't really like to use Jquery in a wordpress situation, but alas...我真的不喜欢在 wordpress 情况下使用 Jquery,但是唉......

I have this script:我有这个脚本:

$('.woocommerce ul li').each(function(i)
  {
     var lenke = $(this).find("a").attr('href');
     $(this).append('&nbsp;&nbsp;<input type="button" class="sendTo" data-id="'+lenke+'" value="E-MAIL">');
});

$('.sendTo').on('click', function(e) {
  var url = $(this).attr("data-id");
  console.log(url);
   var email = '';
   var subject = 'MAIL from ME';
   var emailBody = 'Click to Download ' + url +'.';
      document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody;

}) })

The first code adds an EMAIL-button to each A HREF tag inside (ul)(li) inside a (div).第一个代码将一个 EMAIL 按钮添加到 (ul)(li) 内 (div) 内的每个 A HREF 标签。 As well as copy the HREF from the existing A HREF tag and apply that to the button data-id.以及从现有的 A HREF 标记复制 HREF 并将其应用于按钮数据 ID。

The second code opens a standard email client window and add the data-id as a clickable url in the email body.第二个代码打开一个标准的电子邮件客户端窗口,并将数据 ID 添加为电子邮件正文中的可点击 url。

Running this script under a normal HTML page (and in FIDDLE) everything works like a charm.在普通的 HTML 页面(和 FIDDLE)下运行这个脚本,一切都像魅力一样。 Problem is, running it inside my wordpress page... the URL (variable) does not appear in the email body.问题是,在我的 wordpress 页面中运行它...... URL(变量)没有出现在电子邮件正文中。

so the normal output in FIDDLE is like this:所以FIDDLE中的正常输出是这样的:

 CLICK TO OPEN: https://sitename.com/document/doc.pdf

the Wordpress output looks like this: Wordpress 输出如下所示:

 CLICK TO OPEN:

Did I mention working with jQuery in Wordpress is something I don't like ?我有没有提到在 Wordpress 中使用 jQuery 是我不喜欢的?

The question remains, how to I encode the variable (url) into something that wordpress Jquery will send as text, and yet converts it into a clickable link in the email body ?问题仍然存在,如何将变量 (url) 编码为 wordpress Jquery 将作为文本发送的内容,并将其转换为电子邮件正文中的可点击链接?

All and any ideas will be gratefully received.我们将不胜感激地收到所有和任何想法。

I did a test where I removed the text from the variabel sent to the email body.我做了一个测试,我从发送到电子邮件正文的变量中删除了文本。 I sent the URL only and it worked.我只发送了 URL 并且它有效。 So I made sure that the body-variabel didn't contain any code or hidden characters.所以我确保 body-variabel 不包含任何代码或隐藏字符。 This time it worked like a charm.这一次它就像一个魅力。

SO in the end I don't know what made it work, but this little edit did the trick.所以最后我不知道是什么让它起作用了,但是这个小小的编辑成功了。

  var emailBody = 'Click to Download ' + url

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

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