using events / miserver

MiServer is Dyalog's APL-based web development framework

using events / miserver

Postby Gantois on Thu Dec 01, 2016 8:45 am

Hi,

How could I call a APL function when closing a browser? (for instance: pageAA.dyalog?action=closebrowser)? Where should I read/see examples about using events in miserver?

Thanks,
Marco
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Postby MBaas on Thu Dec 01, 2016 10:48 am

http://miserver.dyalog.com/ > References / "Event Handling" should help for the first steps...
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: using events / miserver

Postby Gantois on Thu Dec 01, 2016 11:06 am

Thanks MBaas,
I´ll study..
Cheers
Marco
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Postby Adam|Dyalog on Thu Dec 01, 2016 4:35 pm

Could you give some more details about what you are trying to accomplish? Are you looking to cleanly terminate a user session? Gather statistics? Something else?

The relevant event would be onbeforeunload, but for security reasons callbacks (and other actions too) are not allowed on this event, only a simple value like

Code: Select all
<body onbeforeunload="return 'Write something clever here...'">

or a function that returns a simple value
Code: Select all
<body onbeforeunload="return return myFunction()">
<script>function myFunction() {return "Write something clever here...";}</script>

It used to be that the returned value would be displayed, as if executing
Code: Select all
alert("Write something clever here...");

which you could achieve in MiServer with
Code: Select all
∇Compose
:Access Public
'onbeforeunload'⎕THIS.Body.Set'return ''Write something clever here...'''

However, all the major browsers (except for IE) have recently ceased to support custom messages. You can still set the attribute with the above code, but only a default message will be displayed, and the user may even have a setting that suppresses such messages too.

Now, while you cannot fully automate a callback on leaving your page or site, you may be able to accomplish what you want with a "Log Out" button/link.

If you just want to know that the user switched to a different page in your site, you can begin all pages by checking if the user just came from another page.

Here are two sample pages on miserver.dyalog.com, demostrating callback techniques:

* Callbacks

* Targets
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Postby Gantois on Wed Jan 18, 2017 9:31 am

Hi Adam. Only now I am seeing your explanation.

I want avoid exit one page clicking on upper right symbol ("X") giving a message and remaining on the page. (I don´t know javascript).

I'll read the cases you wrote and try solve this.

Thanks very much
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Postby Adam|Dyalog on Wed Jan 18, 2017 9:51 am

Hi Gantois,

I'm still not entirely sure what effect you want. Is it one of the following?

1. Prevent the user from closing the browser. If he tries, issue a message to him.

2. Allow the user to close the browser. If he does this, let the server be notified.
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Postby Gantois on Wed Jan 18, 2017 9:16 pm

Hi Adam,

it is the case one:
1. Prevent the user from closing the browser. If he tries, issue a message to him

I have one specific page in my application with one button to close it. It is necessary that the user click it to exit this page. Some actions must be processed before changing to another page or close this page.

In other words, if I Prevent the user from closing the browser I think my problem will be solved. Could I hide the close browse option x" ?. If not, I would like to show a message asking the user to click the exit button of this page.

Cheers
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Postby Adam|Dyalog on Wed Jan 18, 2017 10:28 pm

I'm sorry to disappoint you, but you cannot take control of a visitor's computer through a website. He will always have the option to close his browser. When the user enters your site, you can inform him with a modal dialog that he must click the Exit button to save his changes, etc.

If the user nevertheless tries to close his browser with the [x] button, you can try to pop up a generic message asking if he is sure. You cannot not rely on a custom message getting through, and some users may not see any message at all.

Note that this is not a MiServer limitation, but a universal restriction on websites which is in place so that malicious websites cannot prevent users from leaving.
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Postby Morten|Dyalog on Thu Jan 19, 2017 8:32 am

Note that you DO have an opportunity to clean up when the session handling code times out after a period of inactivity: You can override the onSessionEnd method of the MiServer class and insert your own code to disconnect from databases, close component files and clean up caches etc at that point.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: using events / miserver

Postby Gantois on Sat Feb 04, 2017 10:02 am

thank you for your clarifications.
Marco
Gantois
 
Posts: 80
Joined: Thu Apr 17, 2014 9:44 am


Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest