1 Reply Latest reply on Oct 20, 2015 2:52 PM by Sanford Whiteman

    Calling a Token using Javascript

    Robb Barrett PRD

      I'm building a page and I want it to have information from a token, which I'll pass through a URL parameter.

       

      Example: URL is http://foo.com?token=Token1

       

      What I want to happen is have the page then put in {{my.Token1}} into the HTML.  The problem is that Marketo blocks the token from being created. As you can see below, I present the parameter 3 times: once with square brackets, once with curly braces and once nude. It's blocking the curlies which would create the token.

       

      How do I get it to allow the token to happen?

       

      Code I'm using with URL parameter "first=Link1"

       

      <script>

      document.getElementById("showParamsContainer").innerHTML =

      "<p>Contact Name:<b>[[my."+getParameterByName("first") +"]]</b></p><p>This is the token: {{my."+getParameterByName("first") +"}} <b>End of line.</b><br /><br />"+getParameterByName("first") </script>

       

      Output:

       

      Contact Name:[[my.Link1]]

      This is the token: End of line.

       

      Link1

        • Re: Calling a Token using Javascript
          Sanford Whiteman

          I think you're misunderstanding what's being rendered and where. Your JS is executing in the browser, which does not have access to the server-side tokens. You can't create a client-side HTML fragment with dynamic {{my.<tokenname>}}.

           

          What you can do is inject all the possible fields into the page in an a JSON object (or individual JS vars) and then read that var in your script.

          1 of 1 people found this helpful