Wednesday, December 16, 2009

Should onbeforeunload work in GWT JSNI?

I have a need to implement a "Are you sure you want to leave?"
functionality that can prevent the user from leaving the page (the
same thing Gmail does) when there is unsaved data. All the
documentation I've read says that you can do this by returning a
string from the window.onbeforeunload method. This works if I embed
raw javascript in my html page, but it doesn't seem to work when I
make a native GWT method to do that same thing.

This works:
<script type="text/javascript">
window.onbeforeunload = function () {
return "Hello (in the browser)";
};
</script>


This doesn't:
private native String addOnBeforeUnloadHandler() /*-{
$wnd.onbeforeunload = function () {
return "Hello (in GWT)";
};
}-*/;

Any idea why (and I added an alert in that method to verify that it is
being called to add the onbeforeunload)?

If I have to, I can embed the raw script in the HTML and add a hook
into my GWT code, but that's not as pretty.

--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate