Table of Contents

Class BeforeUnloadEvent

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The BeforeUnloadEvent interface represents the event object for the Windowbeforeunload event, which is fired when the current window, contained document, and associated resources are about to be unloaded.

[Value("BeforeUnloadEvent")]
public class BeforeUnloadEvent : Event
Inheritance
BeforeUnloadEvent
Inherited Members

Remarks

See the Windowbeforeunload event reference for detailed guidance on using this event.

-Windowbeforeunload event

See also on MDN

Constructors

BeforeUnloadEvent()

public BeforeUnloadEvent()

Properties

ReturnValue

IMPORTANT
Deprecated
The returnValue property of the
BeforeUnloadEvent interface, when set to a truthy value, triggers a browser-generated confirmation dialog asking 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.
[Value("returnValue")]
public string ReturnValue { get; set; }

Property Value

string

returnValue is initialized to an empty string ("") value.Setting it to just about any truthy value will cause the dialog to be triggered on page close/reload, however note that it also requires sticky activation. In other words, the browser will only show the dialog if the frame or any embedded frame receives a user gesture or user interaction. If the user has never interacted with the page, then there is no user data to save, so no legitimate use case for the dialog.

NOTE
A generic browser-specified string is displayed in the dialog. This cannot be controlled by the webpage code.

Remarks

NOTE

returnValue is a legacy feature, and best practice is to trigger the dialog by invoking PreventDefault() on the BeforeUnloadEvent object, while also setting returnValue to support legacy cases. See the Windowbeforeunload event reference for detailed up-to-date guidance.

See also on MDN