window.onload = function () { var opener = window.opener; var notifyParent = function (eventName, eventData) { // Backwards compatibility layer for old mobile apps which // look for very specific URLs. This should come before the // location.hash change below since this doesn't trigger a URL // change event but changing the hash does. // TODO: Remove this by November 4th! history.pushState({}, document.title, '/next/login-success/'); // Change the hash, to signal mobile apps. See the help article: // https://help.disqus.com/customer/en/portal/articles/472096 window.location.hash = encodeURIComponent(eventName); if (!opener) return; const { disqusauth = '', disqusauths = '' } = Object.fromEntries(document.cookie.split('; ').map(c => c.split('='))); const extendedEventData = { ...eventData, disqusauth, disqusauths, } try { // This is the old, deprecated direct-access method for // IE8 and IE9 since postMessage does not work there for // cross-origin popups opener.DISQUS.Bus.trigger(eventName, extendedEventData); } catch (err) { var msg = JSON.stringify({ scope: 'client', name: eventName, data: extendedEventData, }); // Post to both secure and insecure origins since we don't know // which one is our opener on. It's not impossible to figure it // out but this is simply easier. opener.postMessage(msg, 'http://disqus.com'); opener.postMessage(msg, 'https://disqus.com'); // Additionally post to Polls because it has different origin opener.postMessage(msg, 'http://polls.services.disqus.com'); opener.postMessage(msg, 'https://polls.services.disqus.com'); } }; var closeWindow = function () { if (opener) return window.close(); // If the window doesn't have an opener, this page was likely opened // in the same window as the discussion embed, such as in a native app's // web view component. If that's the case, check the discussion url that // we store at the beginning of the login process to determine where to // go next. var sessionStorage = window.sessionStorage; try { var discussionUrl = sessionStorage && sessionStorage.getItem('discussionUrl'); if (discussionUrl) return window.location.assign(discussionUrl); } catch (err) { // Fall through } // If there's an error or no discussionUrl, we can make our best guess // that the discussion is two pages back. This won't always be the case, // such as if the user clicks any links in the login window, but it // should be the case most of the time. window.history.go(-2); }; try { notifyParent( '!auth:success', {"sessionId": "27e74f42-18a6-11f1-7cac-120c0a7012db", "message": "", "log_event": ""} ); } finally { // setTimeout is necessary because iOS does not allow you to close the // popup immediately. It also has serious issues about doing things // on the parent page when the popup is still open so this should // be closed as soon as it sends the necessary info to the parent. if (opener) setTimeout(closeWindow, 300); // close the window no matter what } };