2

how to set my own message here, on my own language
Whatever is set as returnValue the resulting message is Changes you made may not be saved.

window.addEventListener("beforeunload", function(event){
    if(saved == false){
        event.preventDefault();
        event.returnValue = "You didn't save changes";
    }
});
Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
qadenza
  • 9,025
  • 18
  • 73
  • 126
  • @imvain2 - seems not possible. Is this the thru? this is 10 years ago – qadenza Feb 16 '21 at 19:30
  • "seems not possible", that's exactlywhy it's a good question – The Bomb Squad Feb 16 '21 at 20:07
  • @TheBombSquad - can't believe. So stupid. What can be a security risk if I write my own message. The same message I can write on any click on page. Thanks anyway – qadenza Feb 16 '21 at 20:52
  • oh.. thing is.. I get your feeling but if you can customise the things.. there probably would be a way to prevent a user from ever coming off(BUT I AGREE, THEY SHOULD LET U CUSTOMISE MESSAGE >:{) – The Bomb Squad Feb 16 '21 at 21:02

1 Answers1

3

Modern versions of browsers removed feature of custom messages (due to security reasons, I suppose).

Chrome from v > 51, Firefox > 4

Safari from v > 9.1

You can bind some callback, yet with no change in message in prompt.

Edit: found a very good documentation with compatibility graph here

Aziza Kasenova
  • 1,501
  • 2
  • 10
  • 22