Web: Confirmation Message / Pop Up when leaving page with exceptions

Hi all,

At this moment I am trying to figure out how I can show a pop-up when leaving the page or when clicking on some of the buttons of the page. At this point I have managed this with the confirmation message, just by clicking on a Back button. So it only works for one button. But this does not work when clicking on some menu items (different e-space) or the browser back/refresh/home button. Or just simply moving away to a different URL. 

I have also tried the Jquery with OnBeforeUnload function, but then the confirmation message will pop up on every change of the page. And when it is executed, the page gets refreshed when you select 'Cancel'. That is not the wished situation. 

Wished situation:
I want to show a Pop-up message when leaving the page, but with some exceptions. In this case the exception should be by clicking on one specific button where the pop-up does not have to be shown. Is there a way I could show a pop-up (an Outsystems Pop-Up preferred) when leaving this one specific page? The problem here are the menu items (which are located in a different module) and the back/refresh/home button of the browser and moving to a different URL. 

Hello Martijn,

I think this is not easy to do and may not work on every browser.
I tested the OML attached in chrome only.

It does not work if the user does not interact with the page either.

Basically, I keep in JavaScript if the user CAN or CAN'T leave the page and check this in the OnBeforeUnload event.

It does not refresh the page if you cancel.

Hope this helps 

P.S. If you search, I am pretty sure you will find other topics here in the forum related to this.

Cheers.

Hi Eduardo,

Many thanks! This does not really suit the situation to be honest. Nevertheless I really appreciate your invested time! I was searching the forums, but couldn't find anything that had the answer to this situation. 


Hi Martijn

I don't think you can do exactly what you want, unfortunately.

It is not possible to open an OutSystems Popup on page leaving if you use the OnBeforeUnload, and it is not possible to catch this event any other way, so if the person closes the page on the tab, for example, you can't prevent unless you use this event (that is very limited).

Web applications have its advantages over Desktop, but there are some limitations also.

Cheers.

Hi Eduardo,

Thanks again. I did a bit more research and indeed this idea is not really "low-code" and can not be done in the way we prefer. I reviewed your code and created a new one, this can be used only on the page without having to create JS in the preparation and screen action. 

SyntaxEditor Code Snippet

window.onbeforeunload = function (inEvent) {
    var noPopup = ["<TEXTOFELEMENT>"];
   if (noPopup.indexOf($(inEvent.srcElement.activeElement).text().toUpperCase()) > -1) {
        // show no popup
   } else {
    (inEvent || window.event).returnValue = "";
   }
}

Regards