Skip to content

Instantly share code, notes, and snippets.

@subzey
Last active June 29, 2020 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subzey/8655beed82f72755d32962d0ce4b9c1b to your computer and use it in GitHub Desktop.
Save subzey/8655beed82f72755d32962d0ce4b9c1b to your computer and use it in GitHub Desktop.
new window right away
<!doctype html>
<html>
<head>
<title>New window right away open test</title>
</head>
<body>
<button id="openwnd">Open a new window</button>
<script>
const pageTemplate = '<h1>Loading...</h1>';
document.querySelector('#openwnd').addEventListener('click', (e) => {
e.preventDefault();
const url = URL.createObjectURL(new Blob([
'<h1>Loading...</h1>'
], {type: 'text/html;charset=utf-8'}))
const wnd = window.open(url);
fetch('/404/', { method: 'POST' })
.catch(() => {
// We don't care how does server exactly respond
})
// artificial delay
.then(() => new Promise(r => setTimeout(r, 500)))
.then(() => {
URL.revokeObjectURL(url);
wnd.location.href = 'https://example.com/';
});
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment