Svelte tries its best to infer the correct namespace from the element's surroundings, but it's not always possible. You can make it explicit with an `xmlns` attribute:
@ -73,7 +72,7 @@ Svelte tries its best to infer the correct namespace from the element's surround
## `<svelte:window>`
```svelte
<svelte:windowon:event={handler}/>
<svelte:windowonevent={handler}/>
```
```svelte
@ -86,13 +85,12 @@ Unlike `<svelte:self>`, this element may only appear at the top level of your co
```svelte
<script>
/** @param {KeyboardEvent} event */
function handleKeydown(event) {
alert(`pressed the ${event.key} key`);
}
</script>
<svelte:windowon:keydown={handleKeydown}/>
<svelte:windowonkeydown={handleKeydown}/>
```
You can also bind to the following properties:
@ -117,7 +115,7 @@ All except `scrollX` and `scrollY` are readonly.
## `<svelte:document>`
```svelte
<svelte:documenton:event={handler}/>
<svelte:documentonevent={handler}/>
```
```svelte
@ -129,7 +127,7 @@ Similarly to `<svelte:window>`, this element allows you to add listeners to even
As with `<svelte:window>`, this element may only appear the top level of your component and must never be inside a block or element.
Similarly to `<svelte:window>`, this element allows you to add listeners to events on `document.body`, such as `mouseenter` and `mouseleave`, which don't fire on `window`. It also lets you use [actions](/docs/element-directives#use-action) on the `<body>` element.
@ -152,7 +150,7 @@ Similarly to `<svelte:window>`, this element allows you to add listeners to even
As with `<svelte:window>` and `<svelte:document>`, this element may only appear the top level of your component and must never be inside a block or element.