windows onload function

From disqus, 1 Week ago, written in Plain Text, viewed 17 times.
URL https://pb.dynavirt.com/view/e613cfee Embed
Download Paste or View Raw
  1.  window.onload = function () {
  2.             var opener = window.opener;
  3.  
  4.             var notifyParent = function (eventName, eventData) {
  5.                 // Backwards compatibility layer for old mobile apps which
  6.                 // look for very specific URLs. This should come before the
  7.                 // location.hash change below since this doesn't trigger a URL
  8.                 // change event but changing the hash does.
  9.                 // TODO: Remove this by November 4th!
  10.                 history.pushState({}, document.title, '/next/login-success/');
  11.  
  12.                 // Change the hash, to signal mobile apps. See the help article:
  13.                 // https://help.disqus.com/customer/en/portal/articles/472096
  14.                 window.location.hash = encodeURIComponent(eventName);
  15.  
  16.                 if (!opener)
  17.                     return;
  18.  
  19.                 const {
  20.                   disqusauth = '',
  21.                   disqusauths = ''
  22.                 } = Object.fromEntries(document.cookie.split('; ').map(c => c.split('=')));
  23.  
  24.                 const extendedEventData = {
  25.                   ...eventData,
  26.                   disqusauth,
  27.                   disqusauths,
  28.                 }
  29.  
  30.                 try {
  31.                     // This is the old, deprecated direct-access method for
  32.                     // IE8 and IE9 since postMessage does not work there for
  33.                     // cross-origin popups
  34.                     opener.DISQUS.Bus.trigger(eventName, extendedEventData);
  35.                 } catch (err) {
  36.                     var msg = JSON.stringify({
  37.                         scope: 'client',
  38.                         name: eventName,
  39.                         data: extendedEventData,
  40.                     });
  41.  
  42.                     // Post to both secure and insecure origins since we don't know
  43.                     // which one is our opener on. It's not impossible to figure it
  44.                     // out but this is simply easier.
  45.                     opener.postMessage(msg, 'http://disqus.com');
  46.                     opener.postMessage(msg, 'https://disqus.com');
  47.  
  48.                     // Additionally post to Polls because it has different origin
  49.                     opener.postMessage(msg, 'http://polls.services.disqus.com');
  50.                     opener.postMessage(msg, 'https://polls.services.disqus.com');
  51.                 }
  52.             };
  53.  
  54.             var closeWindow = function () {
  55.                 if (opener)
  56.                     return window.close();
  57.  
  58.                 // If the window doesn't have an opener, this page was likely opened
  59.                 // in the same window as the discussion embed, such as in a native app's
  60.                 // web view component. If that's the case, check the discussion url that
  61.                 // we store at the beginning of the login process to determine where to
  62.                 // go next.
  63.                 var sessionStorage = window.sessionStorage;
  64.                 try {
  65.                     var discussionUrl = sessionStorage && sessionStorage.getItem('discussionUrl');
  66.                     if (discussionUrl)
  67.                         return window.location.assign(discussionUrl);
  68.                 } catch (err) {
  69.                     // Fall through
  70.                 }
  71.  
  72.                 // If there's an error or no discussionUrl, we can make our best guess
  73.                 // that the discussion is two pages back. This won't always be the case,
  74.                 // such as if the user clicks any links in the login window, but it
  75.                 // should be the case most of the time.
  76.                 window.history.go(-2);
  77.             };
  78.  
  79.             try {
  80.                 notifyParent(
  81.                     '!auth:success',
  82.                     {"sessionId": "27e74f42-18a6-11f1-7cac-120c0a7012db", "message": "", "log_event": ""}
  83.                 );
  84.             } finally {
  85.                 // setTimeout is necessary because iOS does not allow you to close the
  86.                 // popup immediately. It also has serious issues about doing things
  87.                 // on the parent page when the popup is still open so this should
  88.                 // be closed as soon as it sends the necessary info to the parent.
  89.                 if (opener)
  90.                     setTimeout(closeWindow, 300);  // close the window no matter what
  91.             }
  92.         };
  93.    

Reply to "windows onload function"

Here you can reply to the paste above

captcha