Skip to content

Instantly share code, notes, and snippets.

@bellbind
Created Jun 4, 2020
Embed
What would you like to do?
[DOM][browser] simple AbortController example
<!doctype html>
<html>
<head>
<script type="module">
// https://dom.spec.whatwg.org/#interface-AbortController
const ac = new AbortController();
document.querySelector("#aborted").textContent = ac.signal.aborted;
ac.signal.addEventListener("abort", ev => {
console.log("aborted"); // onabort spawned only once
document.querySelector("#aborted").textContent = ac.signal.aborted;
});
document.querySelector("#abort").addEventListener("click", ev => {
ac.abort();
});
</script>
</head>
<body>
<h1>DOM AbortController Example</h1>
<button id="abort">abort</button>
<label>aborted: <span id="aborted"></span></label>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment