Oracle Apex 4.2 Dynamic action with custom event “beforeunload” not working

▼魔方 西西 提交于 2021-01-29 14:15:05

问题


So i have created a custom dynamic action that is supposed to run "beforeunload" (in case user closes the tab/browser unexpectedly or navigates away from the page in a manner not intended). This dynamic action runs a simple plsql procedure ( http://prntscr.com/qz0a6c ). A few days ago the Chrome browser updated to version 80 and in this new version "beforeunload" is disallowed and now my dynamic action does not work.

Does anyone have an idea on how I could build this functionality differently? Apex 4.2 is in question.


回答1:


I guess you are hitting Disallow sync XHR in page dismissal So to turn your DA to asynchronous one try to set Wait for result property of your dynamic actions to false.




回答2:


Here's a complete answer that you should be able to adapt to your situation.

  1. Create a new table to record send beacon data.

    create table beacons (
      id        number generated always as identity primary key,
      app_user  varchar2(255),
      date_sent date,
      data      varchar2(4000)
    );
    

    I used a varchar2 for the data but that could be a CLOB if needed. I'll be passing the data in using the p_clob_01 parameter for Ajax.

  2. Create an Application Process named RECEIVE_BEACON in the Shared Components. Use the following code for the PL/SQL code:

    insert into beacons (
      app_user,
      date_sent,
      data
    ) values (
      :APP_USER,
      sysdate,
      apex_application.g_clob_01
    );
    
  3. Create a Dynamic Action named Window beforeunload. Set Event to Custom, Custom Event to beforeunload, Selection Type to JavaScript Expression, and JavaScript Expression to window.

  4. Select the Action for the Dynamic Action created in step 3. Set the Action to Execute JavaScript Code. Copy/paste the following into the Code field.

    var beaconData = {
      test: 'value'
    };
    
    var formData = new FormData();
    
    formData.append('p_flow_id', '&APP_ID.');
    formData.append('p_flow_step_id', '&APP_PAGE_ID.');
    formData.append('p_instance', '&APP_SESSION.');
    formData.append('p_debug', '');
    formData.append('p_request', 'APPLICATION_PROCESS=RECEIVE_BEACON');
    formData.append('p_clob_01', JSON.stringify(beaconData));
    
    navigator.sendBeacon('/pls/apex/wwv_flow.ajax', formData);
    

Save your changes and run the page. Then refresh the page to trigger the Dynamic Action and send the beacon. This example shows how you can send random data from JavaScript but also get session-related data, such as the user name.



来源:https://stackoverflow.com/questions/60115946/oracle-apex-4-2-dynamic-action-with-custom-event-beforeunload-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!