How do I create a mailto link with a subject line that dynamically fills in the current page URL?

Rhonda's Avatar

Rhonda

24 Sep, 2015 09:50 PM

We have a link in the footer of our website that is a mailto link to send our web team website feedback. Unfortunately, I never know what page they're referring to. I would like to add the URL if possible, or some version of the current page location to the subject line of the email.

This script is in a static block with some JavaScript to keep out spammers. I'm open to other ways to keep spammers out too.

<!-- Script for email protection generated at w2.syronex.com/jmr/safemailto/ -->
<script type="text/javascript">// <![CDATA[
var v2="I3XVYGRW3Q3Q2PAHJ4BJ5FJRJ6";var v7=unescape("*F%2174%2616%1D%26V3F5%20%25%0AS%21%29V%22d7.C");var v5=v2.length;var v1="";for(var v4=0;v4<v5;v4++){v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));}document.write('<a href="javascript:void(0)" onclick="window.location=\'mailto:'+v1+'?subject=Cuyamaca%20College%20Website%20Feedback'+'\'">'+'Website Feedback<\/a>');
// ]]></script>

  1. 1 Posted by Ryan Griffith on 25 Sep, 2015 01:30 PM

    Ryan Griffith's Avatar

    Hi Rhonda,

    I think you could accomplish this using a Velocity Format and the $currentPage variable. Specifically, you could do something like the following:

    #set ($emailSubject = "Cuyamaca College Website Feedback: ${currentPage.siteName}/${currentPage.path}")
    <!-- Script for email protection generated at w2.syronex.com/jmr/safemailto/ --> 
    <script type="text/javascript"><![CDATA[#protect 
    var v1="";
    var v2="I3XVYGRW3Q3Q2PAHJ4BJ5FJRJ6";
    var v7=unescape("*F%2174%2616%1D%26V3F5%20%25%0AS%21%29V%22d7.C");
    var v5=v2.length;
    var v6="${_EscapeTool.url($emailSubject)}";
    for(var v4=0;v4<v5;v4++){v1+=String.fromCharCode(v2.charCodeAt(v4)^v7.charCodeAt(v4));}
    document.write('<a href="javascript:void(0)" onclick="window.location=\'mailto:'+v1+'?subject='+v6+'\'">'+'Website Feedback<\/a>'); 
    #protect]]></script>
    

    So basically use the $currentPage variable to provide context for the calling page when generating the JavaScript. Additionally, you can use the Escape Tool to generate the subject string so it's easier to read/maintain.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Rhonda on 25 Sep, 2015 03:38 PM

    Rhonda's Avatar

    Thank you, Ryan!

    ________________________________

  3. 3 Posted by Ryan Griffith on 25 Sep, 2015 05:04 PM

    Ryan Griffith's Avatar

    Not a problem at all, Rhonda.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  4. Ryan Griffith closed this discussion on 25 Sep, 2015 05:04 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac