1

I am creating a function that prevent the user when he reload the page or press a back space or press back button of Browser . i try the following code..

$wnd.beforeunload=function()
 {
    return "hello";
 }

it is working with simply java script but not in jsni . i also used

Window.addWindowClosingHandler(new ClosingHandler()
{
    @Override
    public void onWindowClosing(ClosingEvent event)
    {
        event.setMessage("Are you sure?");
    }
});

this is working with page refreh and closing, but not working with back button of browser and backspace ...pleace HELP..

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

1

I have already posted an answer in the same context.

Please have a look at promt user on backspace and browser backbutton in gwt for complete code with screenshots.

Try with any option:

  • History.addValueChangeHandler
  • WindowClosingHandler
  • Event.addNativePreviewHandler
  • $wnd.onbeforeunload
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • Braj I try this, but it is not working on back button of browser . is there any possible method that prompt user on back button just like a closing handler ? –  Apr 26 '14 at 05:28
  • onkeydown working in both FF and chrome but in FF event.cancle is not working –  Apr 26 '14 at 06:03
  • @user3364549 Thanks a lot. I have just modified my post. Please have a look. I am still working on Back button of Browser. I'll come back with some solution. – Braj Apr 26 '14 at 08:17
  • there is a probleam its not working in devlopment mode but work on tomcat . –  Apr 26 '14 at 10:39
  • Thanks a lot again for all your findings. – Braj Apr 26 '14 at 10:44
  • @user3364549 I noticed one thing. can you tell me what is the difference between `$wnd.onbeforeunload` and `$wnd.beforeunload`? – Braj Apr 26 '14 at 11:06
  • 1
    onunload is responsible for executing an instruction when the page is closed. It also causes issue with IE and AJAX. onbeforeunload is more efficient because it does not run in competition with the actual closing of the window and is triggered before onunload I know Opera used to not acknowledge onbeforeunload - not sure if they've fixed that, but I always register the listener for both to be safe: –  Apr 26 '14 at 11:20