Struct Window

Source
pub struct Window(/* private fields */);
Expand description

The Window object represents a window containing a DOM document.

(JavaScript docs)

Implementations§

Source§

impl Window

Source

pub fn alert(&self, message: &str)

The Window.alert() method displays an alert dialog with the optional specified content and an OK button.

(JavaScript docs)

Source

pub fn confirm(&self, message: &str) -> bool

The Window.confirm() method displays a modal dialog with an optional message and two buttons: OK and Cancel.

(JavaScript docs)

Source

pub fn local_storage(&self) -> Storage

The local_storage property allows you to access a local Storage object.

It is similar to the Window::session_storage. The only difference is that, while data stored in local_storage has no expiration time, data stored in session_storage gets cleared when the browsing session ends - that is, when the browser is closed.

(JavaScript docs)

Source

pub fn session_storage(&self) -> Storage

The session_storage property allows you to access a session Storage object for the current origin.

It is similar to the Window::local_storage, The only difference is that, while data stored in local_storage has no expiration time, data stored in session_storage gets cleared when the browsing session ends.

A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.

(JavaScript docs)

Source

pub fn location(&self) -> Option<Location>

Returns a Location object which contains information about the URL of the document and provides methods for changing that URL and loading another URL.

(JavaScript docs)

Source

pub fn request_animation_frame<F: FnOnce(f64) + 'static>( &self, callback: F, ) -> RequestAnimationFrameHandle

You should call this method whenever you’re ready to update your animation onscreen. This will request that your animation function be called before the browser performs the next repaint. The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation. request_animation_frame() calls are paused in most browsers when running in background tabs or hidden iframes in order to improve performance and battery life.

The callback method is passed a single argument, a f64, which indicates the current time when callbacks queued by requestAnimationFrame() begin to fire. Multiple callbacks in a single frame, therefore, each receive the same timestamp even though time has passed during the computation of every previous callback’s workload. This timestamp is a decimal number, in milliseconds, but with a minimal precision of 1ms (1000 µs).

(JavaScript docs)

Source

pub fn history(&self) -> History

Returns the global History object, which provides methods to manipulate the browser history.

(JavaScript docs)

Source

pub fn inner_width(&self) -> i32

Returns the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.

(JavaScript docs)

Source

pub fn inner_height(&self) -> i32

Returns the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.

(JavaScript docs)

Source

pub fn outer_width(&self) -> i32

Returns the width of the outside of the browser window. It represents the width of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.

(JavaScript docs)

Source

pub fn outer_height(&self) -> i32

Returns the height of the outside of the browser window. It represents the height of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.

(JavaScript docs)

Source

pub fn page_y_offset(&self) -> f64

The read-only Window property pageYOffset is an alias for scrollY; as such, it returns the number of pixels the document is currently scrolled along the vertical axis (that is, up or down), with a value of 0.0 indicating that the top edge of the Document is currently aligned with the top edge of the window’s content area.

(JavaScript docs)

Source

pub fn page_x_offset(&self) -> f64

This is an alias for scrollX.

(JavaScript docs)

Source

pub fn device_pixel_ratio(&self) -> f64

The ratio in resolution from physical pixels to CSS pixels

(JavaScript docs)

Source

pub fn get_selection(&self) -> Option<Selection>

Returns a Selection object representing the range of text selected by the user or the current position of the caret. (Javascript docs)

Trait Implementations§

Source§

impl AsRef<Reference> for Window

Source§

fn as_ref(&self) -> &Reference

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Window

Source§

fn clone(&self) -> Window

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Window

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Window> for EventTarget

Source§

fn from(value: Window) -> Self

Converts to this type from the input type.
Source§

impl From<Window> for Reference

Source§

fn from(value: Window) -> Self

Converts to this type from the input type.
Source§

impl IEventTarget for Window

Source§

fn add_event_listener<T, F>(&self, listener: F) -> EventListenerHandle
where T: ConcreteEvent, F: FnMut(T) + 'static,

Adds given event handler to the list of event listeners for the specified EventTarget on which it’s called. Read more
Source§

fn dispatch_event<T: IEvent>(&self, event: &T) -> Result<bool, TODO>

Dispatches an Event at this EventTarget, invoking the affected event listeners in the appropriate order. Read more
Source§

impl IWindowOrWorker for Window

Source§

fn set_timeout<F: FnOnce() + 'static>(&self, callback: F, timeout: u32)

Sets a timer which executes a function once after the timer expires. Read more
Source§

fn set_clearable_timeout<F: FnOnce() + 'static>( &self, callback: F, timeout: u32, ) -> TimeoutHandle

Sets a timer which executes a function once after the timer expires and can be cleared Read more
Source§

impl InstanceOf for Window

Source§

fn instance_of(reference: &Reference) -> bool

Checks whenever a given Reference if of type Self.
Source§

impl PartialEq for Window

Source§

fn eq(&self, other: &Window) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReferenceType for Window

Source§

unsafe fn from_reference_unchecked(reference: Reference) -> Self

Converts a given reference into a concrete reference-like wrapper. Doesn’t do any type checking; highly unsafe to use!
Source§

impl<'_r> TryFrom<&'_r Reference> for Window

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(reference: &Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'_r> TryFrom<&'_r Value> for Window

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<EventTarget> for Window

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: EventTarget) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Reference> for Window

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(reference: Reference) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Window

Source§

type Error = ConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Window> for Reference

Source§

type Error = Void

The type returned in the event of a conversion error.
Source§

fn try_from(value: Window) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Window

Source§

impl JsSerialize for Window

Source§

impl StructuralPartialEq for Window

Auto Trait Implementations§

§

impl Freeze for Window

§

impl RefUnwindSafe for Window

§

impl Send for Window

§

impl Sync for Window

§

impl Unpin for Window

§

impl UnwindSafe for Window

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.