Skip to Content
0

When onExit() will be executed?

Nov 28, 2016 at 06:53 AM

599

avatar image
Former Member

Hi,

Documentation tells that onExit() calls by framework when view is destroyed.

Does any one know whether Controller's onExit() will be called either on page "refresh" OR closing browser tab.?

Thanks,

Srinath

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
avatar image
Former Member Nov 29, 2016 at 10:28 AM
0

Ok.

Is there any way to distinguish between "refresh" and "tab close" of a Browser by using UI5 ?

Thanks,

Srinath

Show 4 Share
10 |10000 characters needed characters left characters exceeded

yes, i think you can use navigation.type which will return you the navigation type, it will return 1 or 0 (not sure) on browser refresh.

check below code inside beforeunload function.

window.addEventListener("beforeunload", function (oEvt) {

if (oEvt.currentTarget.performance.navigation.type == 1){

alert("refresh called!");

}

});

OR

Store a cookie the first time visits the page, and you can check this key in beforeunload function whether your key is exists or not, if yes then browser refresh called.

Hope this help.

Regards,

Akhilesh

1
Former Member
Akhilesh Upadhyay

Hi Akhilesh,

"navigation.type" for the first time refresh returning "0" and there onwards returning "1".

Thanks,

refresh-0-1.png (290.1 kB)
0
Former Member
Former Member

Hi Akhilesh,

Got the solution for above issue, where we are getting "0" on refresh for the first time.

"For the first time the page was loaded by direct navigation. Then subsequent reloads will set '1' on refresh, because the page is now loaded by reloading."

Thank you so much!!!

By using '1' on refresh i will keep condition to not execute the code.

Thanks,

Srinath

0

good to hear your issue resolved !:)

0
Ulrich Block
Nov 28, 2016 at 08:17 AM
0

On the one hand you can configure to destroy navigational views at routing by configuring the clearTarget property.

Or in case you tear down an app, onExit will be executed as well. Examples could be the tear down of a Fiori app or the iTeardownMyUIComponent() function used at OPA5 testing.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 29, 2016 at 06:45 AM
0

Hi Ulrich,

Thank you for response.

In our app we are not using Routing and it is a Customized UI5 app.

Challenge here is, in our app we are calling 'DestroySession' OData call to kill user session inside "beforeunload" method. 'DestroySession' should execute only Closing of the browser, not on Browser refresh. Unfortunately, "beforeunload" is being called on browser "refresh" also.

I tried to distinguish between "refresh" and "tab close", but no luck.

I tried modifying 'beforeunload' so as to prompt user with options "Leave/Stay", but am unable to get the event on which button user has clicked (Leave/Stay).

So, thought of shifting 'Destroying Session' OData call to onExit(). Trying to see when onExit() will be executed, either on 'refresh of the page' OR 'tab close'.

Thanks,

Srinath

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Unfortunately this cannot be achieved with onExit. It is only be used in the use cases described above.

0
A K Nov 29, 2016 at 10:29 AM
0

Hi- We can find this action on two places.

  1. While destroying running components, this call back will execute.
  2. While getting out from Launchpad App, onExit will execute
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Karthik,

Thank you for your response.

0