Page 1 of 1

Programmatically Close a Web Page

Posted: Thu Nov 16, 2017 6:23 am
by gstenstrom
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()

Re: Programmatically Close a Web Page

Posted: Thu Nov 16, 2017 7:41 am
by jyoung
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

Re: Programmatically Close a Web Page

Posted: Fri Nov 17, 2017 5:52 am
by gstenstrom
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?

Re: Programmatically Close a Web Page

Posted: Fri Nov 17, 2017 9:33 am
by jyoung
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?

Re: Programmatically Close a Web Page

Posted: Sat Nov 18, 2017 2:43 am
by caseywhite
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

Re: Programmatically Close a Web Page

Posted: Sun Dec 24, 2017 2:28 pm
by atostaine
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?

Re: Programmatically Close a Web Page

Posted: Wed Jan 03, 2018 3:40 am
by caseywhite
Not that I am aware of.