confirmation before closing of tab/browser using angular 2 code example
Example 1: javascript confirm tab close
<script>
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Sure?';
}
// For Safari
return 'Sure?';
};
</script>
Example 2: js ask before close chrome
window.onbeforeunload = function() {
return "";
}