In each html page there are an unknown number of anchors with a mailto href. Two things have to be done when loading a poage.
a) replace these mailto anchors with a script,
b) and then execute the script so the visitor can see the output of the script.
For some reason it does not work.
In the head section
<script>
var eml = {
info: 'aW5mb0BleGFtcGxlLmNvbQ==',
serv: 'c2VydmljZUBleGFtcGxlLmNvbQ==',
show: function(em) {
document.write(window.atob(em))
}
};
</script>
In the body, this works:
<script>eml.show(eml['serv'])</script>
In the body, this doesn't work:
<a href="mailto:@serv">more information</a>
<script>
var i, href, regx, str;
var els = document.querySelectorAll('a[href*="mailto:"]');
for (i = 0; i < els.length; i++) {
href = els[i].href;
regx = new RegExp('^mailto:@[a-zA-Z0-9]+$');
if (regx.test(href) && eml[href.substr(8)]) {
str = "<script>eml.show(eml['" + href.substr(8) + "'])<\/script>";
console.log(str);
els[i].outerHTML = str;
}
}
</script>
Many snippets I tried, with and without jQuery, but so far nothing works.
What is the way to do the job?
Thanx. Ronald