52
Views
1
Comments
OnBeforeUnload
Question
Application Type
Reactive
Service Studio Version
11.54.78 (Build 63596)
Platform Version
11.31.0 (Build 43948)

Hello.

When I move the screen, refresh the page, or close the browser, I want to pop up an alert window and when I click cancel, I want to stay on the original screen.


I've seen several posts on the forum with the same problem as mine.

I was able to find a solution like the following image.


However, it doesn't work perfectly.

It pops up an alert window when I try to refresh or close the page,

but when I try to move the screen using the menu button, the event doesn't work.


Can someone help me?

2024-10-12 12-11-20
Kerollos Adel
Champion

@GeonOh Hwang  , 

i try next code and work with me on refresh and move 


window.addEventListener('beforeunload', function(event) {

  event.preventDefault(); // Prevent the default action of closing the window or tab

  return 'Are you sure you want to leave?'; // Display a confirmation message

});

window.addEventListener('blur', function() {

  alert('You are about to leave the page. Are you sure?'); // Display an alert when the window loses focus

});

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.