Skip to content

Instantly share code, notes, and snippets.

@Abbe98
Last active June 12, 2016 23:35
Show Gist options
  • Select an option

  • Save Abbe98/5b5f6db7ee8cbd5dd459ade6ec375b87 to your computer and use it in GitHub Desktop.

Select an option

Save Abbe98/5b5f6db7ee8cbd5dd459ade6ec375b87 to your computer and use it in GitHub Desktop.
// create popup window
var domain = 'http://wikimaps.mapwarper.net';
var myPopup = window.open(domain + '/u/auth/github?omniauth_window_type=newWindow&auth_origin_url=' + window.location.href, 'myWindow');
// periodical message sender
var messenger = setInterval(function() {
var message = 'requestCredentials';
//send the message and target URI
myPopup.postMessage(message, domain);
}, 500);
// listen to response
window.addEventListener('message', function(event) {
// the message listener get's triggered by any URL make sure it's the right one
if (event.origin !== domain) return;
clearInterval(messenger);
console.log(event.data);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment