跳轉到內容

XForms/離開時警告

來自華夏公益教科書

示例程式

[編輯 | 編輯原始碼]

防止使用者從未儲存的資料離開時丟失表單資料

[編輯 | 編輯原始碼]

將此程式碼新增到 global.js

<script type="text/javascript">
        // adding a gmail style function to stop the user from moving away from the page..
        function unloadMessage(){message = "This form has not yet been submitted to the database\nAll data will be lost."
         return message;}
        function setBunload(on){window.onbeforeunload = (on) ? unloadMessage : null;}
        setBunload(true);
</script>

Mozilla 頁面 [1]

IE 手冊 [2]

將 xf:load 操作與 xforms-value-changed 事件結合使用,以呼叫包含 setBunload(true) 的“髒”函式。

同樣,在提交中使用 load 操作來呼叫包含“setBunload(false)”的“乾淨”函式。

function dirty() {
    setBunload(true);
}
function clean() {
    setBunload(false);
}
This one goes in your "submission" element:
<xf:load resource="javascript:clean()" ev:event="xforms-submit-done"/>

and this 
<xf:load resource="javascript:dirty()" ev:event="xforms-value-changed"/>
goes somewhere in the form  - place it at the body-level to capture all change events, or nest it within a more appropriate container.

參考文獻

[編輯 | 編輯原始碼]

此示例取自 2007 年的 Alex Bleasdale。


有關頁面解除安裝函式的 Microsoft 文件

下一頁: 圖形檢視器 | 上一頁: 自定義控制元件
主頁: XForms
華夏公益教科書