How to run javascript function before logout event: logout:before

Hi everyone

I have written an AMD module that I would like to run before user logout. So I have tested my AMD module on pessek_chat_plugins_boot function and everythinh seems to work.

elgg_register_event_handler('plugins_boot', 'system', 'pessek_chat_plugins_boot');

function pessek_chat_init() {

∕* My AMD javascript here*/

}

But when I call my AMD module using logout:before event nothing happen could someone help me ?

My code looks as followed

elgg_register_event_handler('plugins_boot', 'system', 'pessek_chat_plugins_boot');

function pessek_chat_init() {

elgg_register_event_handler('logout:before', 'user', 'handle_before_logout');

}

function function handle_before_logout($event, $object_type, $user){

/*My AMDJavascript is called here but nothing happen */

}

Best regard

 

  • elgg_register_event_handler('plugins_boot', 'system', 'pessek_chat_plugins_boot');
    
    function pessek_chat_init() {

    Are you sure with it? Maybe:

    elgg_register_event_handler('init', 'system', 'pessek_chat_init');
    
    function pessek_chat_init() {

    Check this

  • Sorry I did a mistake.

    I have written an AMD module that I would like to run before user logout. So I have tested my AMD module on pessek_chat_plugins_boot function and everythinh seems to work.

    elgg_register_event_handler('plugins_boot', 'system', 'pessek_chat_plugins_boot'); 
    
    function pessek_chat_plugins_boot() { 
    
    /* My AMD javascript here */
    
    }

    But when I call my AMD module using logout:before event nothing happen could someone help me ?

    My code looks as followed

    elgg_register_event_handler('plugins_boot', 'system', 'pessek_chat_plugins_boot'); 
    
    function pessek_chat_plugins_boot() { 
    
    elgg_register_event_handler('logout:before', 'user', 'handle_before_logout'); 
    
    } 
    
    function function handle_before_logout($event, $object_type, $user){ 
    
    /*My AMDJavascript is called here but nothing happen */ 
    
    }

     

     

  • In first,

    function handle_before_logout($event, $object_type, $user){

    not

    function function handle_before_logout($event, $object_type, $user){

     

    In second, you can not call your JS in this function directly.

    Use traditional elgg_load_js or AMD elgg_require_js

  • Sorry just a mistake about function function durinf copy and paste

    I am not using my js directly.

    I used elgg_define_js and elgg_require_js in pessek_chat_plugins_boot function and  everything work perfectlly but when I do the same thing in handle_before_logout  nothing happen

     

  • You can't run a javascript function on 'logout:before' because this is a PHP event that happens in an action.  Actions do not output a page, which means no javascript is rendered.

    Since the page reloads, the only thing I could think you would need to do with javascript on logout is call a remote service for something (like analytics?).  If that's the case it would be much better to do that in PHP on the event.

    If you absolutely need to do this in javascript you could use some hacky session sniffing to render your js on the next pageload.  Of course this means whatever you are doing is being done after the logout has happened, not before.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking