Issue
This Content is from Stack Overflow. Question asked by Raseone
Thank you for your time.
I’m trying to build a simple script to reverse email addresses as strings so I can use them for visible email addresses, email mailto: links & addresses for the “action” parameter in forms etc… to help avoid simple scraper bots.
I’ve tried a multitude of different methods and I’m probably just too inept at js to get them working. Here’s a partially working sample of what I think would be an ideal situation.
The data I want does show up in the console log but I’m having trouble getting it to show up in any of the html. Any help would be greatly appreciated.
<script>
var contact = "moc.etis@tcatnoc";
function reverseString(str) {
return str.split('').reverse().join('');
document.getElementById('showemail').innerHTML = 'contact';
}
console.log(reverseString(contact));
</script>
<span id="showemail"></span>
<a href="javascript:reverseString('contact');"> Contact </a>
<a href="javascript:void(0);" onload="reverseString(contact);"> Contact </a>
Solution
I don’t understand the question, but if i try to run the code i have as output ‘contact'(reversed). Are you wondering how to print the original string?
In that case i think will work ->
var contact = "moc.etis@tcatnoc";
function reverseString(str) {
str = str.split('').reverse().join('');
document.getElementById('showemail').innerHTML = str;
}
console.log(reverseString(contact));
</script>
<span id="showemail"></span>
<a href="javascript:reverseString(contact);"> Contact </a>
<a href="javascript:void(0);" onload="reverseString(contact);"> Contact </a>
This Question was asked in StackOverflow by Raseone and Answered by nimprota It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.