A Detailed Introduction to JavaScript’s URL() and URLSearchParams() APIs
A Detailed Introduction to JavaScript’s URL() and URLSearchParams() APIs Author: zhangxinxu Published: August 26, 2019 1. A Quick Look at What These Two APIs Do In the past, processing a URL from the address bar required parsing the string ourselves. For example: ```text https:/...
Code: Dispatching a CustomEvent
const event = new CustomEvent('show', {
detail: { message: payload, sentAt: new Date().toLocaleTimeString() }
});
window.dispatchEvent(event);
Result
Waiting for an event...
Code: Listening for the Event Payload
window.addEventListener('show', (event) => {
render(event.detail.message, event.detail.sentAt);
});
Event log
No events yet.