Window
How to use the Window class of the bit Butil?
Usage
To use the browser window features you need to inject the Bit.Butil.Window class and use it like this:
@inject Bit.Butil.Window window @code { await window.AddEventListener(ButilEvents.KeyDown, args => { ... }); await window.Alert("Alert from C#"); }
Methods
AddBeforeUnload, RemoveBeforeUnload:
The beforeunload event is fired when the current window, contained document, and associated resources are about to be unloaded. The main use case for this event is to trigger a browser-generated confirmation dialog that asks users to confirm if they really want to leave the page when they try to close or reload it, or navigate somewhere else. This is intended to help prevent loss of unsaved data (MDN).
AddEventListener, RemoveEventListener:
Sets up a function that will be called whenever the specified event is delivered to the window (MDN).
GetInnerHeight:
Gets the height of the content area of the browser window in px including, if rendered, the horizontal scrollbar (MDN).
GetInnerWidth:
Gets the width of the content area of the browser window in px including, if rendered, the vertical scrollbar (MDN).
IsSecureContext:
Returns a boolean indicating whether the current context is secure (true) or not (false) (MDN).
GetLocationBar:
Returns the locationbar object. For privacy and interoperability reasons, the value of the visible property is now false if this Window is a popup, and true otherwise (MDN).
SetName, GetName:
Gets/Sets the name of the window's browsing context (MDN).
GetOrigin:
Returns the global object's origin, serialized as a string (MDN).
GetOuterHeight:
Gets the height of the outside of the browser window in px (MDN).
GetOuterWidth:
Gets the width of the outside of the browser window in px (MDN).
GetScreenX:
Returns the horizontal distance in px from the left border of the user's browser viewport to the left side of the screen (MDN).
GetScreenY:
Returns the vertical distance in px from the top border of the user's browser viewport to the top side of the screen (MDN).
GetScrollX:
Returns the number of pixels that the document has already been scrolled horizontally (MDN).
GetScrollY:
Returns the number of pixels that the document has already been scrolled vertically (MDN).
Btoa:
Creates a base-64 encoded ASCII string from a string of binary data (MDN).
Atob:
Decodes a string of data which has been encoded using base-64 encoding (MDN).
Alert:
Displays an alert dialog (MDN).
Blur:
Sets focus away from the window (MDN).
Close:
Closes the current window (MDN).
Confirm:
Displays a dialog with a message that the user needs to respond to (MDN).
Find:
Searches for a given string in a window (MDN).
Focus:
Sets focus on the current window (MDN).
GetSelection:
Returns the selection text representing the selected item(s) (MDN).
MatchMedia:
Returns a MediaQueryList object representing the specified media query string (MDN).
Open:
Opens a new window (MDN).
Print:
Opens the Print Dialog to print the current document (MDN).
Prompt:
Returns the text entered by the user in a prompt dialog (MDN).
Scroll:
Scrolls the window to a particular place in the document (MDN).
ScrollBy:
Scrolls the document in the window by the given amount (MDN).
Stop:
This method stops window loading (MDN).
The beforeunload event is fired when the current window, contained document, and associated resources are about to be unloaded. The main use case for this event is to trigger a browser-generated confirmation dialog that asks users to confirm if they really want to leave the page when they try to close or reload it, or navigate somewhere else. This is intended to help prevent loss of unsaved data (MDN).
AddEventListener, RemoveEventListener:
Sets up a function that will be called whenever the specified event is delivered to the window (MDN).
GetInnerHeight:
Gets the height of the content area of the browser window in px including, if rendered, the horizontal scrollbar (MDN).
@inject Bit.Butil.Window window <BitButton OnClick=GetInnerHeight>GetInnerHeight</BitButton> <div>InnerHeight is: @innerHeight</div> @code { private string? innerHeight; private async Task GetInnerHeight() => innerHeight = await window.GetInnerHeight(); }
GetInnerWidth:
Gets the width of the content area of the browser window in px including, if rendered, the vertical scrollbar (MDN).
@inject Bit.Butil.Window window <BitButton OnClick=GetInnerWidth>GetInnerWidth</BitButton> <div>InnerWidth is: @innerWidth</div> @code { private string? innerWidth; private async Task GetInnerWidth() => innerWidth = await window.GetInnerWidth(); }
IsSecureContext:
Returns a boolean indicating whether the current context is secure (true) or not (false) (MDN).
GetLocationBar:
Returns the locationbar object. For privacy and interoperability reasons, the value of the visible property is now false if this Window is a popup, and true otherwise (MDN).
SetName, GetName:
Gets/Sets the name of the window's browsing context (MDN).
GetOrigin:
Returns the global object's origin, serialized as a string (MDN).
@inject Bit.Butil.Window window <BitButton OnClick=GetOrigin>GetOrigin</BitButton> <div>Origin is: @origin</div> @code { private string? origin; private async Task GetOrigin() => origin = await window.GetOrigin(); }
GetOuterHeight:
Gets the height of the outside of the browser window in px (MDN).
@inject Bit.Butil.Window window <BitButton OnClick=GetOuterHeight>GetOuterHeight</BitButton> <div>OuterHeight is: @outerHeight</div> @code { private float outerHeight; private async Task GetOuterHeight() => outerHeight = await window.GetOuterHeight(); }
GetOuterWidth:
Gets the width of the outside of the browser window in px (MDN).
@inject Bit.Butil.Window window <BitButton OnClick=GetOuterWidth>GetOuterWidth</BitButton> <div>OuterWidth is: @outerWidth</div> @code { private float outerWidth; private async Task GetOuterWidth() => outerWidth = await window.GetOuterWidth(); }
GetScreenX:
Returns the horizontal distance in px from the left border of the user's browser viewport to the left side of the screen (MDN).
GetScreenY:
Returns the vertical distance in px from the top border of the user's browser viewport to the top side of the screen (MDN).
GetScrollX:
Returns the number of pixels that the document has already been scrolled horizontally (MDN).
GetScrollY:
Returns the number of pixels that the document has already been scrolled vertically (MDN).
Btoa:
Creates a base-64 encoded ASCII string from a string of binary data (MDN).
@inject Bit.Butil.Window window <BitTextField @bind-Value="btoaValue" /> <BitButton OnClick=EncodeData>EncodeData</BitButton> <div>Encoded data is: @btoaText</div> @code { private string? btoaText; private string? btoaValue; private async Task EncodeData() => btoaText = await window.Btoa(btoaValue!); }
Atob:
Decodes a string of data which has been encoded using base-64 encoding (MDN).
@inject Bit.Butil.Window window <BitTextField @bind-Value="atobValue" /> <BitButton OnClick=DecodeData>DecodeData</BitButton> <div>Decoded data is: @atobText</div> @code { private string? atobText; private string? atobValue; private async Task DecodeData() => atobText = await window.Atob(atobValue!); }
Alert:
Displays an alert dialog (MDN).
@inject Bit.Butil.Window window <BitButton OnClick="@(() => window.Alert("Alert from C#"))">ShowAlert</BitButton>
Blur:
Sets focus away from the window (MDN).
Close:
Closes the current window (MDN).
Confirm:
Displays a dialog with a message that the user needs to respond to (MDN).
@inject Bit.Butil.Window window <BitButton OnClick="@(() => window.Confirm("Confirm from C#"))">ShowConfirm</BitButton>
Find:
Searches for a given string in a window (MDN).
Focus:
Sets focus on the current window (MDN).
GetSelection:
Returns the selection text representing the selected item(s) (MDN).
MatchMedia:
Returns a MediaQueryList object representing the specified media query string (MDN).
Open:
Opens a new window (MDN).
Print:
Opens the Print Dialog to print the current document (MDN).
Prompt:
Returns the text entered by the user in a prompt dialog (MDN).
Scroll:
Scrolls the window to a particular place in the document (MDN).
ScrollBy:
Scrolls the document in the window by the given amount (MDN).
Stop:
This method stops window loading (MDN).