Question

2
Replies
356
Views
Kuresh Surury (Kuresh_Surury)
Areteans Technology Solutions Pvt Ltd
Senior Architect
Areteans Technology Solutions Pvt Ltd
AU
Kuresh_Surury Member since 2013 4 posts
Areteans Technology Solutions Pvt Ltd
Posted: March 6, 2018
Last activity: March 16, 2018
Posted: 6 Mar 2018 18:51 EST
Last activity: 16 Mar 2018 6:56 EDT
Closed
Solved

Display Warning when user leaves Mashup Page

We have a requirement to display an alert message whenever user click on links on the website which would cause user navigating away from pega mashup


Warning.png



In our implementation Pega Mashup is embedded within client website



We were able to achieve this by adding below code before mashup is loaded



  1. <script type="text/javascript">
  2. window.onbeforeunload = function() {
  3. return true;
  4. };
  5. </script>



But we have few scenario where on click on action button user is redirected different webpage within the Website using below snippet where a non auto generated section is render to redirect the user based on certain conditions



We have a requirement to display an alert message whenever user click on links on the website which would cause user navigating away from pega mashup

Warning.png

In our implementation Pega Mashup is embedded within client website

We were able to achieve this by adding below code before mashup is loaded

  1. <script type="text/javascript">
  2. window.onbeforeunload = function() {
  3. return true;
  4. };
  5. </script>

But we have few scenario where on click on action button user is redirected different webpage within the Website using below snippet where a non auto generated section is render to redirect the user based on certain conditions

  1. <script>
  2. setTimeout(function() {
  3. window.top.location.href ='<%=URLContent%>';
  4. }, 3000);
  5. </script>

In above sceanrio we want to disable the wanring pop up from been dispayed to the user

We have tried below option by placing them in non auto generated section before calling URL redirect but its doesn't seem to have any effect

Setting windows.onbeforeunload = null /false

Setting windows.onbeforeunload = function {}

We also tried updating function and using a flag to decide if the onbeforeload function should execute and disabling the flag from within the redirect section but it also didn't have any effect

So we are currently out of options

Any suggestion how to achieve this requirement ?

  1. <script>
  2. window.lastExitAttempt = null ;
  3. window.allowExit = false;
  4. window.onbeforeunload = function (e) {
  5. if (!window.allowExit) {
  6. checkWithUser= true ;
  7. if ( window.lastExitAttempt != null ) {
  8. timediff = new Date().getTime() - window.lastExitAttempt ;
  9. checkWithUser = timediff > (window.leaveCheckTimeout || 10000) ;
  10. }
  11. /&nbsp;Only need to protect for duplicates in IE or Firefox, leaving lastExitAttempt as null will disable this
  12. if (e) {
  13. window.lastExitAttempt = new Date().getTime();
  14. }
  15. if ( checkWithUser ) {
  16. var e = e || window.event;
  17. /&nbsp;For IE and Firefox
  18. if (e) {
  19. e.returnValue = 'You will lose any unsaved data.';
  20. }
  21. /&nbsp;For Safari
  22. return 'You will lose any unsaved data.';
  23. }
  24. }
  25. };
  26. </script>
  27. <script>
  28. function DisableOnload(){
  29. alert("Disabled");
  30. window.allowExit = false;
  31. };
  32. </script>

Data Integration User Experience Support Case Parallel
Moderation Team has archived post, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.