Cookie Syncing - Client 2
by frosas
HTML
<p>Browser ID: <span id="browser-id"></span></p>
JavaScript
// This page ("client") obtains the browser ID from the "hub" page and displays it. Note the ID will be the same no matter which domain this page is being loaded from.
var getBrowserId = function(callback) {
var iframe = document.createElement('iframe');
iframe.src = 'https://s.codepen.io/frosas/debug/eNoQZB';
iframe.style.display = 'none';
addEventListener('message', function(event) {
if (event.source != iframe.contentWindow) return;
callback(event.data.browserId);
});
document.head.appendChild(iframe);
};
getBrowserId(function(browserId) {
document.querySelector('#browser-id').textContent = browserId;
});