Alert message when navigating away from the portal via a content item external link

shill
Mega Sage

Management is requesting an alert to the user when they are clicking on a content item that a user can click on to warn them they are leaving the service portal.  This is to prevent confusion on where this item may be tracked.  This item is a submission form for another system.

This is similar in the way that .GOV sites will warn  you are leaving the site when clicking on a link to a commercial site.  I've attached an example.

Any thoughts on the best way to do this?

1 ACCEPTED SOLUTION

Oleg
Mega Sage

If I understand you correctly, then you can solve the problem by adding event handler on $locationChangeStart on $rootScope. You can place the code in header widget or inside of scripted menu item or in any other part, which will be loaded on every page. The code of the event handler could look like the following:

$rootScope.$on("$locationChangeStart", function(event, next) {
    event.preventDefault();
    // ... do some tests
    $window.location = next;
});

You should execute $window.location.href = next; statement only if you want to allow redirection.

You can find more information about $locationChangeStart event, spSCNavStateManager or spNavStateManager directives and some code examples in my old answer on the question.

To display alert message you can use spModal.

View solution in original post

1 REPLY 1

Oleg
Mega Sage

If I understand you correctly, then you can solve the problem by adding event handler on $locationChangeStart on $rootScope. You can place the code in header widget or inside of scripted menu item or in any other part, which will be loaded on every page. The code of the event handler could look like the following:

$rootScope.$on("$locationChangeStart", function(event, next) {
    event.preventDefault();
    // ... do some tests
    $window.location = next;
});

You should execute $window.location.href = next; statement only if you want to allow redirection.

You can find more information about $locationChangeStart event, spSCNavStateManager or spNavStateManager directives and some code examples in my old answer on the question.

To display alert message you can use spModal.