Javascript email link script issue


I use a bit of Javascript to mask email links in the code and will assemble the mailto link on the fly to keep address from being farmed. When opening a page in the editor containing this it will act like a browser and display the link. It saves the assembled link as raw html, leaving the JS alone. So then on the live page there are two links, the JS one, and the html one. When my client opens and edits the page a few times there will be 4 or five email links created.

Is there a way to avoid this behavior?


Have you tried using the cms disable tags?

         <script type="text/javascript"> Your Script </script>


If the links are inside editable regions, you’ll need to disable the script that obfusctaes them using one of these techniques.

What’s happening is, the page loads in the editor and the script runs, changing the underlying HTML. The editor can’t detect this and doesn’t see a difference between a script or a user “changing” the content, therefore the resulting email address gets published.

This particular type of script is rather tricky to implement in an editable area. If the user edits the link, for example, they may not understand what to put and could easily end up removing it or breaking the link. When possible, we recommend keeping this type of script outside of editable regions :slight_smile:


hmm. I also noticed that it wraps the script in <div data-embed="true"></div>. If I take it out it puts it right back on publish. wrapping the email address in a div makes it return a line instead of be inline. I wish email address masking wasn’t necessary, but in our world today you know it is.

If I wrap in <!--cms-disable--> it doesn’t load the code at all, and when published omits the email address altogether.

The inline email address can’t really be outside the editable region and still be inline with the contact information that the client wants the ability to edit when necessary.

I’ll see what else I can think of.