Question
Endeavour Energy
AU
Last activity: 16 Mar 2018 6:56 EDT
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
In our implementation Pega Mashup is embedded within client website
We were able to achieve this by adding below code before mashup is loaded
- <script type="text/javascript">
- window.onbeforeunload = function() {
- return true;
- };
- </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
In our implementation Pega Mashup is embedded within client website
We were able to achieve this by adding below code before mashup is loaded
- <script type="text/javascript">
- window.onbeforeunload = function() {
- return true;
- };
- </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
- <script>
- setTimeout(function() {
- window.top.location.href ='<%=URLContent%>';
- }, 3000);
- </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 ?
- <script>
- window.lastExitAttempt = null ;
- window.allowExit = false;
- window.onbeforeunload = function (e) {
- if (!window.allowExit) {
- checkWithUser= true ;
- if ( window.lastExitAttempt != null ) {
- timediff = new Date().getTime() - window.lastExitAttempt ;
- checkWithUser = timediff > (window.leaveCheckTimeout || 10000) ;
- }
- / Only need to protect for duplicates in IE or Firefox, leaving lastExitAttempt as null will disable this
- if (e) {
- window.lastExitAttempt = new Date().getTime();
- }
- if ( checkWithUser ) {
- var e = e || window.event;
- / For IE and Firefox
- if (e) {
- e.returnValue = 'You will lose any unsaved data.';
- }
- / For Safari
- return 'You will lose any unsaved data.';
- }
- }
- };
- </script>
- <script>
- function DisableOnload(){
- alert("Disabled");
- window.allowExit = false;
- };
- </script>