SOLVED

jquery ">" getting replaced with ">"

Go to solution
Charles_Sander1
Level 4

jquery ">" getting replaced with ">"

I've got a pretty simple javascript being dropped into a landing page. I created an editable field in the template, so that should I need any javascript on a page, I can just add it when I'm setting a new one up. (in template like this: )

     <script>

            // <![CDATA[

                 {{my.Footer js}}
            // ]]>
      </script>

But... I just ran into an oddball issue. I dropped in a really simple JS and it's converting my "greater than" symbol to html character. Is there a way to prevent this, or does somebody know maybe another way to do the below and avoid the problem? the script won't fire because it's showing "&gt; -1" EDIT: I should add that I did try to escape it with />, but that didn't work either.

$(document).ready(function () {

if (window.location.search.indexOf('choice=chocolate') > -1) {

    alert('yes choc');

} else {

    alert('no choc');

}

});

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: jquery ">" getting replaced with ">"

What token type are you using? Sounds like your token is being encoded, if you are using a guided lp and string field you can add the allowHtml="true" attr and should be fine.

View solution in original post

6 REPLIES 6
Charles_Sander1
Level 4

Re: jquery ">" getting replaced with ">"

update - I solved the problem of > with !=... but that doesn't seem like the best approach. maybe I'm overthinking it.

Anonymous
Not applicable

Re: jquery ">" getting replaced with ">"

What token type are you using? Sounds like your token is being encoded, if you are using a guided lp and string field you can add the allowHtml="true" attr and should be fine.

SanfordWhiteman
Level 10 - Community Moderator

Re: jquery ">" getting replaced with ">"

Not clear what you mean by "editable field" here... if it's a mktoText in a Guided LP, for example, it'll work.

P.S. No need to wait on DOMContentLoaded ("ready"). document.location.search exists the moment the document starts to load.

Charles_Sander1
Level 4

Re: jquery ">" getting replaced with ">"

Ah... the type of field must've been the problem. I was using mktoString, not mktoText. When I changed to mktoText, it worked fine, and didn't overwrite the ">". Maybe it's some protection against injecting script?  Only problem left is the field keeps adding a <div><br /></div> above the code. Doesn't seem to be affecting my layout, but I don't really want that there.

Charles_Sander1
Level 4

Re: jquery ">" getting replaced with ">"

oh... and I just saw Tony Tiexiera's answer. Maybe I'll go back to that, so I don't have to deal with the <div><br/></div>

SanfordWhiteman
Level 10 - Community Moderator

Re: jquery ">" getting replaced with ">"

mktoText is an element, while mktoString is a variable.  They have different rules, and as Tony pointed out the mktoString has two options to be more flexible.

The default rule with mktoString isn't about injecting script, it's that if you don't escape HTML in some contexts, that can break the page  (think about if you wanted to print the script code, not run it). Since the mktoString doesn't know what you're going to do with the value, you have to tell it what you want.