这样做的一种方法是通过 ajax 更新页面项目的会话状态(不正常提交页面),并在由 javascript onbeforeunload 调用时调用更新表的应用程序进程。
创建一个应用程序进程以按需触发,命名为 UpdatePageXOnExit 或其他名称。在该应用程序进程的 PL/SQL 块中,使用 SQL 更新命令以及您希望更新的页面上每个项目的项目状态;类似于以下内容:
BEGIN
UPDATE table_name SET col1 = :PX_ITEM_1, col2 = :PX_ITEM_2, col3 = :PX_ITEM3, col4 = :PX_ITEM_4, col5 = PX_ITEM_5
WHERE (condition... I would suggest ROWIDs to simplify changes to the
fields of the PK; otherwise you will have to create additional
page items for each field of the PK, then set those items to
the values of the PK when the page loads using a before
header page process, and then use those values in this where
clause like this: where col1 = :PX_ORIGINAL_PK_FIELD_1 AND col2 =
:PX_ORIGINAL_PK_FIELD_2 );
END ;
转到该特定页面的页面设置,然后在 JavaScript: Execute On Page Load 部分中,编写如下内容:
window.onbeforeunload = updateOnExit;
在 JavaScript 函数和全局变量声明中,编写如下内容:
function updateOnExit() {
var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=UpdatePageXOnExit',&APP_PAGE_ID.);
get.add('PX_ITEM_1',$x('PX_ITEM_1').value)
get.add('PX_ITEM_2',$x('PX_ITEM_2').value)
get.add('PX_ITEM_3',$x('PX_ITEM_3').value)
get.add('PX_ITEM_4',$x('PX_ITEM_4').value)
get.add('PX_ITEM_5',$x('PX_ITEM_5').value)
gReturn = get.get();
get = null;
// Comment out the following line or not, as per the note in the following paragraph
return 'Are you sure you would like to leave the page?';
}
最后一部分是 AJAX,它更新页面上页面项目的会话状态,这些页面项目在用户端已更改但尚未上传到服务器端,这通常发生在页面提交期间。注意:如果您注释掉 return 语句,则不会有允许用户留在页面上的警告框。如果这是你喜欢的,那就去吧。如果您选择使用警告框,即使用户选择留在页面上,ajax 也会执行页面进程。