Last active
June 29, 2020 12:04
-
-
Save subzey/8655beed82f72755d32962d0ce4b9c1b to your computer and use it in GitHub Desktop.
new window right away
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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