<script type="text/javascript">
  // If the current window is the 'parent', change the URL by setting location.href
  if (window.top == window.self) {
    window.top.location.href = "{{ redirect_uri }}";

  // If the current window is the 'child', change the parent's URL with postMessage
  } else {
    var normalizedLink = document.createElement('a');
    normalizedLink.href = "{{ redirect_uri }}";

    var message = JSON.stringify({
      message: "Shopify.API.remoteRedirect",
      data: { location: normalizedLink.href }
    });
    window.parent.postMessage(message, "https://{{ shop }}");
  }
</script>