Please try is as below.
Note: This is just a sample.Adjust it according to your app.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
Check here for more info : beforeunload