Questions tagged [onbeforeunload]
The onbeforeunload event is triggered before a user navigates away. This event listener can be used to show a confirmation dialog to the user on page leave.
onbeforeunload
919
questions
0
votes
3
answers
78
views
Angular - @HostListener - Completely prevent page refresh
I'm using @HostListener to prevent the window reload. I have implemented my code like following -
@HostListener('window:beforeunload', ['$event'])
unloadNotification($event: any) {
let checkSave = ...
0
votes
1
answer
151
views
addEventListener beforeunload for prompt on leave doesn't work in React
I'm trying to setup a prompt on when the user is leaving the page, my simple code is:
useEffect(() => {
window.addEventListener("beforeunload", (event) => {
event....
0
votes
0
answers
143
views
back button with useNavigate() replace: true is not triggering beforeunload for safari only
I'm using react-router-dom and useNavigate() function. When the user goes from "/home/" to "/home/room", I'm doing navigate("/home/room", { replace: true }) so that when ...
0
votes
1
answer
321
views
Removing the beforeunload event does not work in React
The snippet below is suppose to add and remove event listener handleBeforeUnload. On checking the browser console I see the "inside else" getting printed however loading the page still ...
0
votes
1
answer
198
views
How to run code before exit angular application?
I am trying to add something in local storage when the user exit the angular app without pressing logout (close tab or browser).
Here is what I tried:
@HostListener('window:UnloadHander', ['$event']...
0
votes
0
answers
138
views
Browser back button does not show popup of leave permission in next js
I'm encountering an issue with handling the browser back button in my Next application. I have a useEffect hook set up to listen for the beforeunload event, where I check if latestGeneratedImages is ...
0
votes
0
answers
181
views
onbeforeunload event processing problems on Windows 10 in Chrome and Edge
I'm using onbeforeunload event handler to trigger browser dialog "Do you really want to exit" in case user did some data entry.
Up till lately it worked without problems, but lately browsers ...
1
vote
0
answers
132
views
Confirm leaving the page in an ArcGIS web app builder
I created an app with ESRI ArcGIS Web App Builder. Now I want to ask the user if he wants to leave the page any time he clicks the forward or back button of the browser or if he refreshes the page.
I ...
0
votes
1
answer
150
views
Show window.confirm for prevent changing the URL
Needs to prevent changing url from my component. So, nees to show a message, and if user choose cancel - don't change the URL, if OK - change the URL. How I can make this logic in next 13.4
It's my ...
-1
votes
1
answer
401
views
How to detect when user leaves the web page or not?
I want to trigger a function when the user exits the web page by closing the browser tab or pressing the browser's back button. Currently, I'm using the "beforeunload" and "unload" ...
1
vote
0
answers
102
views
Can I fake a user interaction for beforeunload event to work in chrome?
Since beforeunload event is not triggered unless if there is a user interaction, is it possible to fake the interaction.
I tried having a dummy click or focus on input using jQuery but still ...
0
votes
1
answer
315
views
How do I run code before user leaves the page?
Nothing I've tried does work. I need to run some code before the user leaves the page all:
window.onbeforeunload = function(){
alert(1);
}
window.addEventListener("beforeunload", ...
0
votes
4
answers
328
views
How to save data to database when the user request to leave?
What is the proper way to do that? My goal is to save in database the count of minutes of the video the user has watched until he closed the page and set the video's minutes to where he left off, next ...
0
votes
0
answers
44
views
Do some logic based on propmt in React JS
I want to show a prompt alert when user wants to close or refresh the page in a specific component in react js and based on confirming the refresh or the closing window do some different logic . here ...
1
vote
1
answer
182
views
Angular beforeunload API-Call using fetch
I have a component in Angular 15 that when the window or tab is closed requires an API call to my backend. I tried to solve it like bellow, but apparently this is not a good solution, as using fetch ...