> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: onBeforeUnload(callback: onBeforeUnloadCallback) # Method package: wixDashboard # Method menu location: wixDashboard --> onBeforeUnload # Method Link: https://dev.wix.com/docs/velo/apis/wix-dashboard/on-before-unload.md # Method Description: Registers a [`beforeunload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event) handler for a dashboard page. > **Note:** This function can only be used in page code files for dashboard pages created in the [Wix Editor](https://support.wix.com/en/article/velo-working-with-dashboard-pages) or with [Wix Blocks](https://support.wix.com/en/article/wix-blocks-creating-and-managing-blocks-dashboard-pages). `onBeforeUnload()` accepts a callback that's triggered when a site builder is about to navigate away from a dashboard page or when the browsing context of an app is being unloaded. For example, this can happen when the site builder selects another page from the dashboard's sidebar. The event object passed to the callback function contains a function called `preventDefault()`. If the callback calls `preventDefault()`, navigation away from the page or other context unloading is paused. A dialog is displayed in the dashboard warning the site builder that there may be unsaved data. The site builder can then choose to cancel and stay in the current context or proceed. > **Notes:** > * The `beforeunload` event does not fire when a user closes the browser or refreshes the page. > * You should not assume that the `beforeunload` event will always fire or that the confirmation dialog will always be presented. These behaviors vary depending on the site builder's browser. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Ask for confirmation before unloading unsaved data ```javascript import { onBeforeUnload } from 'wix-dashboard'; // ... const { remove } = onBeforeUnload((event) => { // Check if there is unsaved data on the page if (unsavedPageData) { event.preventDefault(); } }); // ... // Remove the onBeforeUnload event handler remove(); ``` ---