When browsing Facebook in the latest Chrome on OSX, I noticed that beginning to type in a comment box and clicking another link or pressing the back button triggers a confirmation window asking if I'd like to leave:
Being an old school developer, I had believed that the only possibility was to attach an onbeforeunload
event to the page to handle the back button click. I know you can do a global binding on the anchors to simulate onbeforeunload
, but I was surprised they managed to have a custom styled confirmation and not the stock, ugly looking confirmation dialog.
How did they do it? Is this some kind of HTML5 window history or pushState event trigger?