0

I am using a CMS to host landing pages. Each of the landing pages begin with about 600 lines of JavaScript which is identical across landing pages. This script basically validates the form and adds in some conditional functionality. I am not the creator of the script and my knowledge of JavaScript is limited.

My initial goal was to remove the JS and place it into an external file and link to it via <script src="">, however, this does not work. I've worked with support on this and they said basically, "the CMS will not action on the script in the reference file."

My secondary option is to leave the standard <script type="text/JavaScript"></script> tags in the head section (embedded, not linked), cut the JS out from between and place into a field merge within the CMS, then populate that field merge between those tags. Everything populates, but the field merge is transitioning a few characters to their character entities, e.g.

< is &lt;
> is &gt;
& is &amp;
' is &39;
" is &quot;

Just those five are being converted and this is how my JS will populate into the landing page. Unfortunately it is breaking the functionality by doing so. A sample of what this looks like when populated in the landing page:

else if (args.Type == &#39;multisel&#39;) {<br />
var selCount = 0;<br />
for (var i = 0; i &lt; Element.length; i++) {<br />
if (Element[i].selected &amp;&amp; Element[i].value != &#39;&#39;) {<br />
selCount += 1;<br />

as you can see it is also adding those br tags, but I imagine I could simply minify to get rid of those.

I've researched adding an additional script below to convert these entities back into characters, though I have been unsuccessful so far. Is it even possible to add a subsequent script within the code or landing page that would reference the populated JS and convert the entities back into characters?

Places I've been and methods I've attempted thus far:
Convert special characters to HTML in Javascript
Unescape HTML entities in Javascript?
Encode html entities in javascript
HTML Entity Decode
http://developwithstyle.com/articles/2010/06/29/converting-html-entities-to-characters/
http://www.webdeveloper.com/forum/showthread.php?136026-RESOLVED-convert-HTML-Entities-into-normal-characters

Community
  • 1
  • 1
keithiopian
  • 123
  • 1
  • 2
  • 11
  • Your CMS field-merge capability probably has some checkbox for an option called something like "Don't escape inserted stuff as HTML" or "insert as HTML" or "raw HTML". Check that box. By the way, what is the problem you are trying to solve? Anyway, inserting JS into a page using field-merge sounds like a horrific hack. –  Aug 14 '15 at 18:05
  • Thanks for the thought torazaburo, unfortunately it does not. My goal is to have one centralized place to edit the JavaScript that spans about 1000+ pages. – keithiopian Aug 14 '15 at 18:07

0 Answers0