Enter a search term above to see results...
On This Page
Browser Utilities
The Browser utilities provide functions for common tasks in browser environments, such as copying text, handling keyboard events, and fetching text content.
Functions
copyText
Copies the provided text to the clipboard.
Parameters
Name | Type | Description |
---|---|---|
text | string | The text to copy to the clipboard |
Example
Browser Support This function uses the modern
navigator.clipboard.writeText
API. Ensure compatibility with your target browsers or provide a fallback for older browsers.
getKeyFromEvent
Extracts a standardized key representation from a keyboard event.
Parameters
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The keyboard event object |
Returns
A string representing the key pressed, including any modifier keys (e.g., “ctrl+a”).
Example
Modifier Keys This function handles modifier keys (Ctrl, Alt, Shift, Meta) and combines them with the pressed key. It also normalizes some key names for consistency.
getText
Fetches text content from a given URL.
Parameters
Name | Type | Description |
---|---|---|
src | string | The URL to fetch the text from |
Returns
A Promise that resolves with the fetched text content.
Example
Usage Note This can be used on the server to load static assets like templates or css
openLink
Opens a URL, optionally in a new window.
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to open |
options | object | Optional configuration |
Options
Name | Type | Default | Description |
---|---|---|---|
newWindow | boolean | false | Whether to open in a new window |
target | string | null | Target attribute for the link |
event | Event | null | Event object to prevent default behavior |
Example
getText
Fetches text content from a URL.
Component Usage -
getText
can be used to retrieve html and css for use in a web component on the client from a separate file without a compilation step.
Parameters
Name | Type | Description |
---|---|---|
src | string | The URL to fetch from |
Returns
A Promise that resolves with the text content.
Example
getJSON
Fetches and parses JSON content from a URL.
Parameters
Name | Type | Description |
---|---|---|
src | string | The URL to fetch from |
Returns
A Promise that resolves with the parsed JSON content.