Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Window

Functions

addEventListener
(
type
:
String
capture
:
Bool
listener
:
Function(Html.Event, a)
)
:
Function(Void)

Adds a listener to the window and returns the function which removes this listener.

listener =
  Window.addEventListener("click", true, (event : Html.Event) {
    Debug.log(event)
  })
addMediaQueryListener
(
query
:
String
listener
:
Function(Bool, a)
)
:
Function(Void)

Adds a media query listener to the window and returns the function which removes this listener.

listener =
  Window.addMediaQueryListener("(max-width: 320px)", (matches : Bool) {
    Debug.log(matches)
  })
alert
(
message
:
String
)
:
Promise(Void)

Shows the default alert popup of the browser with the given message.

This function returns a promise but blocks execution until the popup is closed.

Window.alert("Hello World!")
confirm
(
message
:
String
)
:
Promise(Result(String, Void))

Shows the default confirm popup of the browser with the given message.

This function returns a promise but blocks execution until the popup is closed.

Window.confirm("Are you ready?")

Gets the width of the scrollbar.

Window.getScrollbarWidth() == 10
height
:
Number

Returns the height of the window in pixels.

Window.height() == 768
href
:
String

Returns the windows URL as a string.

Window.href() == "https://www.example.com"
isActiveURL
(
url
:
String
)
:
Bool

Returns true if the given url is the same as the current url of the page.

Window.isActiveURL("https://www.example.com")
jump
(
url
:
String
)
:
Promise(Void)

Like Window.navigate(), but also triggers a jump to the start of the document or the hash, if it exists.

Window.jump("/new-url")
matchesMediaQuery
(
query
:
String
)
:
Bool

Returns true if the given media query matches.

Window.matchesMediaQuery("(max-width: 320px)")
navigate
(
url
:
String
)
:
Promise(Void)

Sets the URL of the window. If there is a route defined for this URL, runs its handler. Updates the navigation history.

Window.navigate("/new-url")
open
(
url
:
String
)
:
Promise(Void)

Opens the given url in a new window or tab.

Window.open("https://www.google.com")
prompt
(
label
:
String
current
:
String
)
:
Promise(Maybe(String))

Shows the default prompt popup of the browser with the given message and value.

This function returns the entered text as a Maybe(String) and blocks execution until the popup is closed. If the user cancelled the popup it returns Maybe::Nothing.

case (Window.prompt("How old are you?")) {
  Maybe::Just(value) => Debug.log(value)
  Maybe::Nothing => Debug.log("User cancelled")
}

Returns the scrollable height of the window in pixels.

Window.scrollHeight() == 768
scrollLeft
:
Number

Returns the horizontal scroll position of the window in pixels.

Window.scrollLeft() == 100
scrollTop
:
Number

Returns the vertical scroll position of the window in pixels.

Window.scrollTop() == 100

Returns the scrollable width of the window in pixels.

Window.scrollWidth() == 1024
setScrollLeft
(
position
:
Number
)
:
Promise(Void)

Sets the vertical scroll position of the window in pixels.

Window.setScrollLeft(100)
setScrollTop
(
position
:
Number
)
:
Promise(Void)

Sets the horizontal scroll position of the window in pixels.

Window.setScrollTop(100)
setTitle
(
title
:
String
)
:
Promise(Void)

Sets the windows title.

Window.setTitle("New Title!")
setUrl
(
url
:
String
)
:
Promise(Void)

Sets the URL of the window.

Window.setUrl("/new-url")
title
:
String

Returns the windows title.

Window.title() == "Title!"
triggerJump
:
Promise(Void)

Triggers a jump to the current location on the page.

When a page loads and the current url has a hash #anchor-name, the browser automatically jumps to the element with the matching id or to the anchor tag with the matching name <a name="anchor-name">. This behavior does not happen when the history is manipulated manually.

This function triggers that behavior. When there is a hash in the current URL, it jumps to it, otherwise it jumps to the start of the document.

url
:
Url

Returns the current Url of the window.

Window.url().host == "www.example.com"
width
:
Number

Returns the width of the window in pixels.

Window.width == 1024