Hi all,

I am using the Javascript below on a screen. This code will make sure a confirmation message will pop up when leaving the screen. This code is working perfectly on one page, but is not working on a different page. And is used exactly the same.The code is not even read by the page when using the debugger mode in Chrome. 

How it works;

1. On the page we have a form and when changes are made a variable will be filled with "X" and assigned to an input on the screen (With an ajax refresh). This input field is placed on the screen with style = "display:none;"
2. When leaving the screen by using one of the buttons, menu or browser back button a confirmation message is shown when it notice that the input is not empty.
3. But there are some exceptions, because on some buttons this must not work. 

This code is placed on the screen Javascript properties. The weird thing is that it is not working on a different page. It looks like something is suppressing the code. 

Does anyone know what to do or how I can get this working? 


SyntaxEditor Code Snippet

window.onbeforeunload = function (inEvent) {
    var noPopup = ["TEXTOFBUTTON", "TEXTOFBUTTON2"];
   if (noPopup.indexOf($(inEvent.srcElement.activeElement).text().toUpperCase()) > -1 ||
 !$("[id $= 'wtHiddenInputJS' ]")[0].value ) {
        // show no popup
   } else {
    (inEvent || window.event).returnValue = "";
   }
}

Martijn de Pijper wrote:

Hi all,

I am using the Javascript below on a screen. This code will make sure a confirmation message will pop up when leaving the screen. This code is working perfectly on one page, but is not working on a different page. And is used exactly the same.The code is not even read by the page when using the debugger mode in Chrome. 

How it works;

1. On the page we have a form and when changes are made a variable will be filled with "X" and assigned to an input on the screen (With an ajax refresh). This input field is placed on the screen with style = "display:none;"
2. When leaving the screen by using one of the buttons, menu or browser back button a confirmation message is shown when it notice that the input is not empty.
3. But there are some exceptions, because on some buttons this must not work. 

This code is placed on the screen Javascript properties. The weird thing is that it is not working on a different page. It looks like something is suppressing the code. 

Does anyone know what to do or how I can get this working? 


SyntaxEditor Code Snippet

window.onbeforeunload = function (inEvent) {
    var noPopup = ["TEXTOFBUTTON", "TEXTOFBUTTON2"];
   if (noPopup.indexOf($(inEvent.srcElement.activeElement).text().toUpperCase()) > -1 ||
 !$("[id $= 'wtHiddenInputJS' ]")[0].value ) {
        // show no popup
   } else {
    (inEvent || window.event).returnValue = "";
   }
}

Hi Martijn,

First thing why are you using javascript for a popup, which is already provided by Outsystems.

it gives popup in the browser, not of outsystems.

Regards,

Amreen

Hi Martjin,

Did you check already in the console, in the fault page, if you have any JavaScript error?
JavaScript errors will prevent the execution of further JavaScript, for example.

You can also debug the JavaScript to see if it is running and something else is wrong.

Cheers.

@Armeen, 

Thanks for your reply. I know that there is a function within Outsystems, but it should also work in the browser when using the back button for example when leaving the page. 

The weird thing is that the code is working on a different screen and does not work on an other screen. Seems like something is suppressing it and can not figure out what that could be. 

@Eduardo

No there is no fault to be found unfortunately. It does not even read or sees the code. It really looks like something is suppressing the JS on the screen. 

Is the JavaScript really present in the fault's page, in your code?
Is this page in the same module as the other page you have where this is working? Could be a problem with one module calling a page in a different module but from a previous version, like an outdated problem?
Are you placing the JavaScript in the theme JavaScript, the Page JavaScript, etc?

It can be seen on the faults page, but will not show the prompt.
This page is indeed in the same module as the other screen.
The script is in the page javascript properties. Also tried to use a expression with the JS. Also that will not work. 


How much "different" is your screen than the one that works?

EDIT
And the JavaScript is Exactly the same on both screens?

Hi Eduardo,

There are no really differences. It is of course a different screen, but nothing special on it that could be of influence. And the script and method is indeed exactly the same.