Programmatically Close a Web Page

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
gstenstrom
Posts: 17
Joined: Thu Feb 16, 2017 8:35 am

Programmatically Close a Web Page

Post by gstenstrom » Thu Nov 16, 2017 6:23 am

Hi,
I have simple Web page that calls a server module to download a file. I would like to automatically close the Web page when the server routine is successful.
I have search high and low and not finding anything.
Looking for the Javascript equivalent to window.close()

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Programmatically Close a Web Page

Post by jyoung » Thu Nov 16, 2017 7:41 am

Don't know about a way to directly close a page, but if you are downloading a file from a Server Module, such as a CSV, and writing directly to the response, you can you can use target(new) on the component declaration in your client component.

Code: Select all

srvroutine name(Download) response(#response) session(*REQUIRED)

#response.ContentString += "my content"

#response.AttachmentFileName := "myfile.csv"
#response.ContentType := "text/csv"

endroutine

Code: Select all

define_com class(#CMGFBCReportModule.Download) name(#Download) target(New)
Then you just call Execute instead of ExecuteAsync. The browser automatically opens a new tab downloads the file and closes the tab when its complete.

Joe

gstenstrom
Posts: 17
Joined: Thu Feb 16, 2017 8:35 am

Re: Programmatically Close a Web Page

Post by gstenstrom » Fri Nov 17, 2017 5:52 am

Maybe explaining what I'm doing might help.

I have an email where the body is HTML. It has a link to this Web Page that extracts the URL Parameters and runs the Server Module.

http://mskgbn1t:81/dcxpgmlib/dev/ocwpgs ... GST142.xls
The Web Page just serves as a step to call the Server Module passing the "xfile" parameter

Is there a way to call a Server Module Directly with URL Parameters?

jyoung
Posts: 653
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Programmatically Close a Web Page

Post by jyoung » Fri Nov 17, 2017 9:33 am

The problem with something like a window.close is that most browsers won't allow you to close the window via script if you did not open it via script.

If however, in your situation you can use javascript to close the window, you may try creating a widget that contains a method to close the window via javascript. Then you can you can call that method from the page, after server module completes AND the widget has been initialized.

I don't think ServerModules access the querystring (besides its own parameters) I think all the data comes from the request body. Perhaps someone from LPC can weigh in.

If the file already exists, is it possible to serve the file directly instead of going through a server module?

caseywhite
Posts: 101
Joined: Thu May 26, 2016 1:17 am

Re: Programmatically Close a Web Page

Post by caseywhite » Sat Nov 18, 2017 2:43 am

Just use the WAM URL format to call a server module directly. Example is below showing that I am calling a server module with identifier CPWREDIRE and passing the parm SURNAME with a value of FRED.

Code: Select all

http://localhost:85/CGI-BIN/lansaweb?wam=CPWREDIRE&webrtn=usRedirect&part=DEM&lang=ENG&f(SURNAME)=FRED

atostaine
Posts: 414
Joined: Wed Jan 20, 2016 7:38 am

Re: Programmatically Close a Web Page

Post by atostaine » Sun Dec 24, 2017 2:28 pm

caseywhite wrote:
Sat Nov 18, 2017 2:43 am
Just use the WAM URL format to call a server module directly. Example is below showing that I am calling a server module with identifier CPWREDIRE and passing the parm SURNAME with a value of FRED.

Code: Select all

http://localhost:85/CGI-BIN/lansaweb?wam=CPWREDIRE&webrtn=usRedirect&part=DEM&lang=ENG&f(SURNAME)=FRED
Is this documented anywhere?
Art Tostaine

caseywhite
Posts: 101
Joined: Thu May 26, 2016 1:17 am

Re: Programmatically Close a Web Page

Post by caseywhite » Wed Jan 03, 2018 3:40 am

Not that I am aware of.

Post Reply