我正在开发一个企业应用程序,其中表单是动态生成的,我们无法控制代码。表单中的大多数控件都有以下代码与之相关:
<select name="s_10_1_1_0" onchange = 'SWESubmitForm(document.SWEForm10_0,s_5,"","1-E0RHB7")' id='s_10_1_1_0' tabindex=1997 >
<input type="text" name='s_10_1_11_0' value='' onchange = 'SWESubmitForm(document.SWEForm10_0,s_7,"","1-E0RHB7")' id='s_10_1_11_0' tabindex=1997 maxlength="30">
我们希望在用户使用页眉或页脚中的链接导航到其他页面时,能够呈现一个“确定/取消”对话框。
我已经使用以下代码绑定了 onbeforeunload 事件,并向用户呈现了一个“确定/取消”对话框。
//this identifies the unique page name
var viewName = $('input[name="SWEView"]').val();
// if I am on desired page bind the event so that now dialog is presented to user
if(viewName == "XRX eCustomer Create Service Request View"){
$(window).bind('beforeunload', function(){
return 'Your Inquiry has not been submitted yet.';
});
}
但问题在于,每当用户更改表单中任何字段的值时,此对话框都会出现(我认为这是由于onchange事件中存在SWESubmitForm代码所致)。
我希望在用户单击表单外的任何其他链接或换句话说,将onbeforeunload对话框绑定到页面上的选择性事件(包括关闭窗口)时,才会出现该对话框。
请帮忙。