• Resolved andrewmoise

    (@andrewmoise)


    So if I include in my TCM code block the following code:

    <!-- Special offer timer implementation -->
    
    <script>
    function getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    (and things continue from there)

    Then what actually gets expanded into the HTML when my page is served is:

    <script defer="defer">
    function getCookie(cname) {
        var name = cname + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return &quot;&quot;;
    }
    

    So the entity expansion with ampersands causes syntax errors which cause the Javascript not to work… I can just put the Javascript into a separate file but it’s easier for me to work being able to edit the short script right in the TCM. Is there any way to fix this and still have the code editable in the TCM?

    Thanks in advance for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello

    we are sorry for the inconvenience, we are still working to find a solution for this issue.

    The issue is generated by the comparison operator used in the loop for, it is probably mistaken as the start of an html tag and then the PHP function used to sanitize the code goes to clean up everything after it

    maybe you can invert the comparison operator

    for(var i = 0; ca.length>i; i++) {

    instead of

    for(var i = 0; i<ca.length; i++) {

    Could you please edit your script, then check if the javascript function getCookie works as expected?

    Thank you

    We’re in the process of fixing this problem and will release an update soon.

    Hello @andrewmoise,

    Release 2.0.13 fixes the problem you’ve reported here.

    -Oliver

    Thread Starter andrewmoise

    (@andrewmoise)

    Hey, that’s excellent! Thank you for the fix + the quick response.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Javascript code in TCM gets quotes changed’ is closed to new replies.