User name and email in URL parameters

답변함

1 댓글

  • Karen Snyder
    Community Moderator

    Amanda Morphew-Ulm you can do this by putting an empty div into new_request_page.hbs and then using JavaScript to insert the <a href element. The HelpCenter object which is accessible to JavaScript contains the user name and email.

    The steps would be:

    1. In new_request_page.hbs, insert the following wherever you want the link to appear. This provides a div that the JavaScript can place the <a href element in.

    <div id="insertGoogleUrl"></div>

    2. Insert the following code before the first line of new_request_page.hbs. It inserts the <a href element into the div. It gets the user name and email from the HelpCenter object. It also replaces any blanks in the user name with %20, because blanks in URLs need to be encoded (see https://www.w3schools.com/tags/ref_urlencode.ASP).

    <script>
      $(document).ready(function () {
        var htmlString = '<a href="https://google.com?name=' +
             HelpCenter.user.name.replace(' ', '%20') + '&email=' + HelpCenter.user.email
              + '">Visit Google</a>';
        $('#insertGoogleUrl').append(htmlString);
     });
    </script>

    Please note that this code works only in themes where jquery can be used (templating API v1). Please let me know if you have any questions.

     

    0

댓글을 남기려면 로그인하세요.

Zendesk 제공