Search code examples
javascripthtmlemaildynamicmailto

Can I dynamically set the recipient of mailto: using only HTML and JavaScript depending on URL used to access the site?


I have 5 different websites that all use the same privacy html page but depending on which site they accessed it from I want the email to change dynamically.

For example, lets say I access the privacy page from Site A and click the privacy@example.com to send an email I want that email to be sent to privacy-siteA@example.com, if I access the same privacy page from Site B and click the same email I want it to send to privacy-siteB@example.com.

Is something like this possible with just HTML and JavaScript?

Thanks!


Solution

  • var l=window.location+'';
    l=l.replace(/http(s*):\/\/(www\.)*/,'');
    l=l.split('/')[0]; //get the domain
    var mailto='privacy-'+l+'@example.com';