views:

39

answers:

1

Hi guys,

I am using window.onbeforeunload in my javascript. This works perfectly in IE but is not triggered in Firefox.

I checked on different links in stackoverflow.... In it I read that window.onbeforeunload is not supported by firefox. Is this true?

If yes, can you please tell me a different way to call app.deleteAccount(key) on close of browser. Here is my javascript. Please look at the deleteFile() and dontDeleteFile() methods.

<script type="text/javascript">
//Event handler for body onload
function confirmDeleteFile(){
    var secured =document.r_form.Secure[1].checked;
    alert("confirmDeleteFile : "+secured);
    if(secured){
     var agree=confirm("Are you sure you wish to continue?");
     if (agree){
      //document.form1.submit();
      return true;
     }
     else
     return false ;
    }
  //  submitForm();
    return true;
   }
function deleteFile() {
 alert('inside deleteFile() but outside window.onbeforeunload');
window.onbeforeunload = function(){
 var key = DOMAIN+'::' + elem('userName').value;
alert('inside deleteFile()');
    app.deleteAccount(key)  
    alert('Unloading!');
   } 
}
function dontDeleteFile() {
 alert('inside dontDeleteFile() but outside window.onbeforeunload');
 window.onbeforeunload = function(){ 
  alert("Not deleting"); 
    } 
 }

function validateFormOnSubmit(theForm) {
var reason = "";
var userName = theForm.username.value;
var pin = theForm.pin1.value;
var PAM = theForm.pam.value;
var organization = theForm.organization.value;
//reason += validateUsername(theForm.username);
reason += validateEmpty(theForm.pam);
reason += validatePinMatch(theForm.pin1,theForm.pin2);
reason += validatePin(theForm.pin1,theForm.pin2);
if (reason != "") {
if(!confirmDeleteFile()){
 return false;
}
alert("Some fields need correction:\n" + reason);
return false;
}
else{
 if(!confirmDeleteFile()){
  return false;
 }

<% String url  =  request.getServerName().toString();
 int port = request.getServerPort();
 String contextPath = request.getContextPath();
%>
 var servlet = "arcotebank.az"; //AroctEBanking Servlet
  var url = BASE_URL + '/' + servlet;
     var query = 'lang=en&reqid=1&version=1.1';
     query += '&device=' + urlEncode(navigator.userAgent);
     query += '&uid=' + urlEncode(userName);
     query += '&code=' + urlEncode(PAM); 
     query += '&pin=' + urlEncode(pin);
     query += '&usePin=' + usePin+'&method=arcotOTPEnroll&organization='+organization; 
//alert("url=>"+url + '?' + query);
  var xml = app.openUrl(url + '?' + query) + '';
  //alert("xml=>"+xml);
  if(appError()){
    alert("applet error");
  }
var domain = getDomain(url);
app.provisionAccount(domain, xml);
  if(appError()){
    alert("applet error");
   }
var acc = app.getAccount(DOMAIN + '::' + userName);
     if(acc!=null){
     <%String formSubmitAction1 =
            URLEncoderDecoder.encodeURL(
                        formAction,
                        "Action.2FA.Arcot.Navigation.LogoutActionCalled=Y",cm);%>
                theForm.action ='<%=formSubmitAction1%>';
                var secured =document.r_form.Secure[1].checked;
               alert("line 131 "+secured);
                if(secured){
                 deleteFile();
    }else{
    dontDeleteFile();
    }               
       theForm.submit();
     }else{
    document.getElementById("error").innerHTML = "Failed to Create ArcotOTP";
     }
}
}
function resetForm(){
     var form = document.forms[0]; 
     form.username.value = '';
     form.pam.value = '';
     form.pin1.value = '';
     form.pin2.value = '';
  }
function validateUsername(fld) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores

if (fld.value == "") {
fld.style.background = 'Yellow';
error = "You didn't enter a username.\n";
} else if ((fld.value.length < 5) || (fld.value.length > 15)) {
fld.style.background = 'Yellow';
error = "The username should contain more than 4 characters.\n";
} else if (illegalChars.test(fld.value)) {
fld.style.background = 'Yellow';
error = "The username contains illegal characters.\n";
} else {
fld.style.background = 'White';
}
return error;
}
function validateEmpty(fld) {
 var error = "";

 if (fld.value.length == 0) {
 fld.style.background = 'Yellow';
 error = "You didn't enter Personal Assurance Message \n"
 } else {
 fld.style.background = 'White';
 }
 return error;
 }

function validatePin(pin1,pin2){
 var error="";

   if(pin1.value!=pin2.value){
    pin1.style.background = 'Yellow';
    pin2.style.background = 'Yellow';
    error += "Pin numbers dont match\n";
     //alert("Pin numbers dont match");

     }
     return error;

 }
 function validatePinMatch(pin1,pin2){
 var error="";
 if(pin1.value==""){
  //elem('otp').style.background = 'Yellow';
  pin1.style.background = 'Yellow';
  error += "Pin number cannot be empty\n";
  //alert("Pin number cannot be empty");

  }
 if(pin2.value==""){
  //elem('otp').style.background = 'Yellow';
     pin2.style.background = 'Yellow';
  error += "Confirm Pin number cannot be empty\n";
  //alert("Pin number cannot be empty");

  }
  return error;
 }

</script>
A: 

window.onbeforeunload is supported by Firefox and all major browsers. It should be implemented as a function that returns a string, which will be used as the message in the confirmation dialog.

kgiannakakis
Can you tell me why its not getting invoked in my code snippet
mujeeb
Also ... can you please tell me if its supported in Google Chrome and opera??
mujeeb
See my edited answer. onbeforeunload is supported in all major browsers. You should return a string from the implementation of the function.
kgiannakakis
Is it possible to call a applet function from it?? Like in the deleteFile() method of my code i have called app.deleteAccount(key)... This is the applet method. Its not getting called in firefox. Works fine in IE
mujeeb
First test that you can call the applet method in another function. If this is possible, then it probably has to do with the Java plug-in in Firefox. If you have access to the Java code, it will be better to handle this situation there.
kgiannakakis