Skip to content

Instantly share code, notes, and snippets.

@jayphelps
Created May 24, 2016 23:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayphelps/dc8556e72caaf8b2ac5596afcf91498d to your computer and use it in GitHub Desktop.
Save jayphelps/dc8556e72caaf8b2ac5596afcf91498d to your computer and use it in GitHub Desktop.
async window.open()
window.onclick = () => {
// You MUST create the window on the same event
// tick/stack as the user-initiated event (e.g. click callback)
const googleWindow = window.open();
// Do your async work
fakeAjax(response => {
// Change the URL of the window you created once you
// know what the full URL is!
googleWindow.location.replace(`https://google.com?q=${response}`);
});
};
function fakeAjax(callback) {
setTimeout(() => {
callback('example');
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment