Service Portal - Change the text of the Leave Page alert "Leave Site: Changes you made may not be saved." Specifically when we have Cart Items before closing of window

Raviteja BVS
Kilo Explorer

Hello Everyone,
Thanks in advance,

Recently we got a requirement to Change the text of the close browser page alert to change Text. when we have cart items in it.

I tried Customizing and Overriding "spSCNavStateManager" and changing the alert message in this directive and also tried using the below code.

$window.onbeforeunload = function (event) {
var answer = confirm('If you leave this page you are going to lose all unsaved changes, are you sure you want to leave?')
if (!answer) {
event.preventDefault();
}
return answer;
};

 

and 

 

$scope.$on('$locationChangeStart', function( event ) {
//if (!$scope.form.$dirty) return;
var answer = confirm('If you leave this page you are going to lose all unsaved changes, are you sure you want to leave?')
if (!answer) {
event.preventDefault();
}
});

 

Anyone have a suggestion on how to make this possible?

1 REPLY 1

sachin_namjoshi
Kilo Patron
Kilo Patron