Hello,
I've added some logic to the OnClientPasteHtml method in Javascript, which ensures that the <a> tag has a href of "#" and adds a OnClick attribute. We're doing this so that mailto links are (roughly) encoded, so bots do not spam the email address, etc.
This is my code:
function OnClientPasteHtml(sender, args) {
var commandName = args.get_commandName();
var value = args.get_value();
if (commandName == "LinkManager" || commandName == "SetLinkProperties") {
breakme: if (/href="mailto:([^@]+)@([^?"]+)(?:\?subject=([^"]+))?[^>]+>([^<]+)/i.test(value)) {
var valueSplit = value.match(/href="mailto:([^@]+)@([^?"]+)(?:\?subject=([^"]+))?[^>]+>([^<]+)/i);
// Email address
if (typeof valueSplit[1] == "undefined" || typeof valueSplit[2] == "undefined") {
break breakme;
}
var addrPrefix = valueSplit[1];
var addrSuffix = valueSplit[2];
// Subject
var subject = '';
if (typeof valueSplit[3] !== "undefined") {
subject = valueSplit[3];
}
// Text
var linkText = '';
if (typeof valueSplit[4] !== "undefined") {
linkText = valueSplit[4];
}
// Final output example = <a onclick="href='mailto:'+'first.name'+'@'+'domain.com'+'?subject=hello world'" href="#">Email Me.</a>
var valueFinal = '';
if (Prototype.Browser.IE) {
// TODO: Fix IE bug
}
else{
valueFinal = "<a onclick=\"href='mailto:'+'" + addrPrefix + "'+'@'+'" + addrSuffix + "'+'?subject=" + subject + "'\" href=\"#\">" + linkText + "</a>";
}
args.set_value(valueFinal);
}
}
It works perfectly, in Firefox, but I seem to be getting odd results in IE (and possibly Chrome).
When I debug in IE, I can see that valuFinal is in the correct format, but then when you click or view html, the <a> tag changes, to this:
<a onclick="href='mailto:'+'website'+'@'+'domain.com'+'?subject=domain.com feedback'" href="mailto:website@domain.com?subject=domain.com feedback">mailto:website@domain.com?subject=domain.com feedback</a>
As you can see, the href is not a "#" and the link text is being replaced by the same mailto link.
I use Sitecore.NET 7.2 (rev. 140526), which is using Telerik 2012.1.607.35 DLL version.
We don't really want to upgrade any versions so a fix for my current state will be ideal.
Any information will be great! Thanks :)