0

I see that most modern browsers have removed the ability to pass custom message in onbeforeunload dialogs. (feature removed in chrome: https://www.chromestatus.com/feature/5349061406228480).

So i have the following questions..

Why have the modern browsers removed that functionality ? What is their reasoning behind this design? If user has to show custom messages in modern browsers , what do we do now?

stallion
  • 1,901
  • 9
  • 33
  • 52

1 Answers1

1

The reason behind that , is security concerns . As onbeforeunload event may allow attackers to upload some codes which can merge harsh code to client / server sides as well as to the uploaded file.

Ahmed Shahin
  • 74
  • 1
  • 8
  • Thanks for the answer.. What is the alternative to show custom messages on browser tab refresh.? I believe addressing security concern at the expense of limiting customer experience/functionality may not be ideal.. – stallion Oct 10 '21 at 10:11
  • Having said that "If user has to show custom messages in modern browsers , what do we do now?" – stallion Oct 10 '21 at 10:12
  • can you give more details about what you are trying to achive . i might help you with that. – Ahmed Shahin Oct 10 '21 at 10:14
  • During the application flow in react which contains multiple react pages, if the customer clicks browser refresh, all his details from all pages including previous pages are lost, so we want to show custom message upon browser refresh warning customers not to do that and if they do that previous data will be lost – stallion Oct 10 '21 at 10:17
  • why not resolve the problem then ? and keep the data without losing it on refresh ? – Ahmed Shahin Oct 10 '21 at 10:19
  • i am sorry , i suggest that , it could be a function to clear the data but i am just suggesting why not to keep the data as it is on refresh ? – Ahmed Shahin Oct 10 '21 at 10:19
  • on your case , you have 2 senarios to do it . either prevent the users from refreshing the page . Or Keep the data as it is on refresh – Ahmed Shahin Oct 10 '21 at 10:20
  • well, i don't think we can prevent users from refreshing the page in our case or atleast we dont think that customer limitation should be done... Having said that, try composing facebook status and in the middle of it click browser refresh, we can see a warning popup with browser's default message.. i just want to know what people usually consider if they want to have custom message in such case – stallion Oct 10 '21 at 10:25
  • i will add this code for you try it , it should prevnt users from refreshing the page using javascript – Ahmed Shahin Oct 10 '21 at 10:28
  • 1
    Alternativly , you can prevent users from refreshing the page by placing this script within your page – Ahmed Shahin Oct 10 '21 at 10:30
  • actully , i insist to make this online for you , allow me few minutes , i am working on a page now for you – Ahmed Shahin Oct 10 '21 at 10:31
  • remain on this page while i work out this challange :) http://khayalshop.net/testrefresh.a5w – Ahmed Shahin Oct 10 '21 at 10:37
  • https://dev.to/eons/detect-page-refresh-tab-close-and-route-change-with-react-router-v5-3pd check this i am trying to do the same for you – Ahmed Shahin Oct 10 '21 at 10:49
  • i think i found it , but the tweak will not customize the messege however , it will keep the data as it is and it will display your messege before the default messege , you can do this by creating local storage within the browser , the local storage will keep your data as it is and onforunload event u will contact your local storage and display stored messege .i will need time once i am done i will let you know – Ahmed Shahin Oct 10 '21 at 10:57
  • ok test the website now try click on the button refresh and u will see custom msg tell me what you think http://khayalshop.net/testrefresh.a5w – Ahmed Shahin Oct 10 '21 at 12:24
  • i left a textbox for you to write a value on your own in it , on refresh it will not vanish. – Ahmed Shahin Oct 10 '21 at 12:25
  • http://khayalshop.net/testrefresh.a5w is not accessible for me.. it says forbidden – stallion Oct 13 '21 at 11:25
  • i had to remove it sorry i really give up on this , it's not doable – Ahmed Shahin Oct 16 '21 at 15:18
  • No issues...Thank you Ahmed Shahin for your efforts and your help ! Highly appreciated.. – stallion Oct 21 '21 at 07:00