Closing a Web page using Javascript connected to a button
Application Type
Traditional Web
Service Studio Version
11.10.12 (Build 39237)

I followed a post on closing a window  using Javascript.  The solution offered worked (see below).

But as soon as I added some logic it would not close. My logic tests if the user clicked the Save button before closing. Why should this prevent it from working?

Thank you.

Leon


mvp_badge
MVP
Solution

Hi Leon,


When you use an OutSystemsUI Layout, behind the scenes (as you see on the screenshot of the OutSystemsUIWeb clone below), LayoutWidgets web block is included which includes the javascript necessary for Feedback Messages to show:


That's probably the reason why you are experiencing problems related to showing feedback messages. To avoid that, when you start a layout different than the default ones, you should use the webblock LayoutSimple which already incorporates the aforementioned LayoutWidgets:


mvp_badge
MVP

Hi Leon,


There's no reason for it not to work if you're running a screen action (so it has a screen to close).

Have you debugged the code to see that the if node evaluates to False and therefore run the javascript to close the page?


Kind Regards,

João

Yes, I have. Many times to make sure.  If I take out the test, it works. When I put back the test, it doesn't.

mvp_badge
MVP

Hi Leon,


I went ahead and tried myself with the following Javascript window.close(); in a similar logic as you have in an action which is called with method = Ajax Refresh and it works:



I attach the OML with the example, hopefully it will help you understand to get it right in your case.


Kind Regards,
João

TraditionalWebSandbox.oml

Thanks João.

Maybe if I explain another aspect about this case, it may help to solve the problem.

The screen in question is a second entry point of this module.  The strange thing is that when I click on "Close", and the Saved test fails (returns false), nothing happens. I would expect to see the error message. I then close the screen manually and go to the first entry point of the module and the error message appears.  

I am sure that these are connected issues.

Regards,

Leon

mvp_badge
MVP

Hi Leon,


Is your link / button linked to that action set to Ajax Submit?


Besides that, a known cause for Feedback messages not showing is related to not using OutSystems layouts which include scripts necessary to run Feedback messages. Are you using one of the layouts from OutSystems UI or a layout that uses the layout from OutSystems UI in your screen?


Kind Regards,
João

João,

I got this code from on of the posts on the forum:  "window.open('','_self').close()"       

I replaced it with "window.close();"

It is working better but I still have the problem of the error message being presented on the return screen.

I have two entry points.  The screen that has this code is on Entry2.  Now it closes if data is saved (this is an improvement). But if the data is not saved, nothing happens.  The user has to close the screen manually. When the screen activated by Entry1 is run, the error message that the data is not saved, appears.

Thanks for your help so far.

Leon

João, 

I have just noticed that my answer to you last question was not posted for some reason.

I started this particular screen with a blank page. I did not use a OutSystems UI layout.  In the screen actions I notice that the error handling logic is there.

mvp_badge
MVP
Solution

Hi Leon,


When you use an OutSystemsUI Layout, behind the scenes (as you see on the screenshot of the OutSystemsUIWeb clone below), LayoutWidgets web block is included which includes the javascript necessary for Feedback Messages to show:


That's probably the reason why you are experiencing problems related to showing feedback messages. To avoid that, when you start a layout different than the default ones, you should use the webblock LayoutSimple which already incorporates the aforementioned LayoutWidgets:


Thank you João.

I will implement your suggestion.  I am sure it will solve the problem.  I will get back to you if I need any help.

Regards,

Leon

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.