开发者

GWT - Show a custom dialog before window close?

I need to prompt the user to a site usability survey when the user navigate away from the site or try to close the site window. For example, when the user closes the window of my site, I want to show a prompt to say "do you want to take a survey?" , if the user clicks yet, open a new window with the survey link.

Is there a way in GWT to achieve that?

I have tried using Windows.addWindowCLosingHandler

but that only gave me the ability to set a message to ask if the user want to stay on the site or now using ClosingEvent event , event.setMessage("sure?");

thanks开发者_开发知识库


You can use window.onunload but that will be called whenever the user changes the page

Also see here: How to catch user leaving a page and cancelling it


Use the unload method on the body:

<body onUnload="unloadFunction(); return false;">

Then something like this for your js:

function unloadFunction()
 {
     if (confirm("Would you like to take our servey?"))
     {
          window.location.href = 'location_of_your_survey'
     }

     return false;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜