Hello,
I did a package which renders the Ace editor as a HTML widget:
So the user has a second editor in RStudio 
I would like to warn the user when he/she closes the viewer pane without having saved the code. I tried this JavaScript code:
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '';
});
This seems to work fine at first glance:
But there's an issue: look at what happens to the viewer pane when the user presses "Cancel". The toolbar (the icons) of the viewer pane disappear, e.g. the "close" button is not there anymore.
Do you have any suggestion? Thank you.