手動リンクデコレーション
Fanplayrは、ドメイン間でセッションを継続するために必要なパラメータでURLを手動で拡張するためのJavaScript APIを提供します。
- この方法は、グローバルな
window.location
オブジェクトを介したナビゲーションなど、Fanplayrが自動的に処理できない方法でナビゲーションが発生するシナリオで必要です。 - この方法は、リンクデコレーションプロセスを最大限に制御したい開発者にとっても良い選択肢です。
次のユーティリティ関数は、最初にウェブページの上部に定義されるべきです。
javascript
function decorateLink(url) {
try {
return window.fanplayr.decorateLink(url);
} catch (ex) {}
return url;
}
次に、ドメイン間のナビゲーションを引き起こすJavaScriptを、そのユーティリティ関数を使用するように更新します。例えば、ウェブページ上にクリックすると別のドメインのチェックアウトにナビゲートするボタンがあるとします。
html
<!-- 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>
ウェブサイトは次のように更新できます。
html
<!-- 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>