Automatically adding an item to a visitor's Favorites list

    Using a simple JavaScript function, you can automatically add an item to a visitor's Favorites list by updating an existing web form.

     

    Note: This behavior will only function for visitors that are logged into a Secure Zone; the system must be able to identify the visitor in order to display the Favorites list and add the specified item to it.

    First, add the following HTML code to the page:


    <script type="text/javascript" src="/ajaxpro/prototype.ashx"></script>
    <script type="text/javascript" src="/ajaxpro/core.ashx"></script>
    <script type="text/javascript" src="/ajaxpro/converter.ashx"></script>
    <script type="text/javascript" src="/ajaxpro/CMS.FavoriteProcess,Catalyst.Web.CMS.ashx"></script>
    

     

    Then, add the JavaScript function that will add the item to the Favorites list. It will look similar to this:

     

    <script type="text/javascript">
    
    function AddToFavorites() {
      var objectId = '{ tag_itemid}';
      var objectType = 35;
    
      var result = CMS.FavoriteProcess.ServerSideAddToFavorites(objectId, objectType);
       // result is boolean, true or false
    }
    

     

    Finally, edit the source code for the web form to call the function above (AddToFavorites) before it submits the form.

    This strategy adds the item to the visitor's Favorites list before the form is submitted.