using events / miserver

MiServer is Dyalog's APL-based web development framework
Post Reply
Gantois
Posts: 91
Joined: Thu Apr 17, 2014 9:44 am

using events / miserver

Post by Gantois »

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
User avatar
MBaas
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany
Contact:

Re: using events / miserver

Post by MBaas »

http://miserver.dyalog.com/ > References / "Event Handling" should help for the first steps...
Gantois
Posts: 91
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Post by Gantois »

Thanks MBaas,
I´ll study..
Cheers
Marco
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Post by Adam|Dyalog »

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
Gantois
Posts: 91
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Post by Gantois »

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
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Post by Adam|Dyalog »

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.
Gantois
Posts: 91
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Post by Gantois »

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
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: using events / miserver

Post by Adam|Dyalog »

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
Morten|Dyalog
Posts: 460
Joined: Tue Sep 09, 2008 3:52 pm

Re: using events / miserver

Post by Morten|Dyalog »

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.
Gantois
Posts: 91
Joined: Thu Apr 17, 2014 9:44 am

Re: using events / miserver

Post by Gantois »

thank you for your clarifications.
Marco
Post Reply