Manual link decoration

Fanplayr provides a JavaScript API for manually augmenting URLs with parameters needed to continue sessions between domain names.

  • This method is necessary in scenarios where navigation occurs using a method which Fanplayr cannot automatically handle, such as navigation via the global window.location object.

  • This method is also a good choice for developers who want maximum control over link decoration process.

The following utility function should first be defined near the top of your webpage:

function decorateLink(url) {
  try {
    return window.fanplayr.decorateLink(url);
  } catch (ex) {
  }
  return url;
}

Next, update any JavaScript that causes navigation between domains to make use of the utility function. For example, assume there is a button on the webpage navigate to a checkout on a separate domain when clicked:

<!-- https://mystore.com -->
<html>
  <head>
  </head>
  <body>
    <button onclick="navigateToCart">View Cart</button>
    <script>
      function navigateToCart() {
        window.location.href = 'https://mystore.hosted.com/cart/';
      }
    </script>
  </body>
</html>

The website could be updated as follows:

<!-- https://mystore.com -->
<html>
  <head>
  </head>
  <body>
    <button onclick="navigateToCart">View Cart</button>
    <script>
      function decorateLink(url) {
        try {
          return window.fanplayr.decorateLink(url);
        } catch (ex) {
        }
        return url;
      }
    </script>
    <script>
      function navigateToCart() {
        window.location.href = decorateLink('https://mystore.hosted.com/cart/');
      }
    </script>
  </body>
</html>

Last updated