Window
Functions
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)
})
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)
})
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!")
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
Returns the height of the window in pixels.
Window.height() == 768
Returns the windows URL as a string.
Window.href() == "https://www.example.com"
Returns true if the given url is the same as the current url of the page.
Window.isActiveURL("https://www.example.com")
Like Window.navigate()
, but also triggers a jump to the start of the
document or the hash, if it exists.
Window.jump("/new-url")
Returns true
if the given media query matches.
Window.matchesMediaQuery("(max-width: 320px)")
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")
Opens the given url in a new window or tab.
Window.open("https://www.google.com")
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
Returns the horizontal scroll position of the window in pixels.
Window.scrollLeft() == 100
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
Sets the vertical scroll position of the window in pixels.
Window.setScrollLeft(100)
Sets the horizontal scroll position of the window in pixels.
Window.setScrollTop(100)
Sets the windows title.
Window.setTitle("New Title!")
Sets the URL of the window.
Window.setUrl("/new-url")
Returns the windows title.
Window.title() == "Title!"
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.
Returns the current Url
of the window.
Window.url().host == "www.example.com"
Returns the width of the window in pixels.
Window.width == 1024