From our email exchange
"Nate, what Thiago tried to do was make it so that if a user has changed something on page, and they click next on any paginated item, then it will ask them to first click save before doing it.
It would be nice if we could do the same thing, but not for pagination, but for any type of event.
Imagine a user fills out a form in portlet A, forgets to click save. Mean while, portlet B has a bunch of regular href links. If he clicks on any of them, it moves him out of the page.
We would like some global way to say, once you do X, we now call some JS method that will tell the user he needs to click save.
One possible API would be:
Liferay.Util.addWarnUserForLeavingPage('some-key-1'); // please rename the method
That will add it to the JS cache of keys.
If the user then clicks save (and it goes via Ajax and somehow it's in an OK state again, we then trigger)
Now, if the user clicks and tries to go to another page. We're ok and the user will not be warned.
The reason it needs to be key based is because multiple portlets could add different keys / states. Let me know if this makes sense. Thanks Nate."