tags:

views:

27

answers:

2

Hi.

I'm trying to simulate onclick event in a h:commandButton when I close my browser.

Here is my code:

<body onBeforeUnload='closingBrowser()'>


function closingBrowser() {
    document.getElementById('main:commandButtonHidden').onclick();
    return false;
}

This javascript function call the function associated with my button which has this definition:

<h:commandButton id="commandButtonHidden"
   value="checkPasswords().Login" 
   onclick="javascript:checkPasswords();" actionListener="#{init.closingBrowser}" />

and checkPasswords():

function checkPasswords() {
  alert("checkPasswords");
  return true;
}

This function has nothing interesting because what I want is the function in my actionListener.

This works perfect in IE and FF, but not in chrome or Opera.

The alert always is fired in all browsers, but the actionListener NO, just in IE and FF, and it has no sense.

Somebody knows anything about this.

Thanks

A: 

Wild guessing: try firing a click event, instead of accessing the onclick callback.

document.getElementById('main:commandButtonHidden').click();
Matchu
A: 

Hi.

Could you be more explicit??

Is there something wrong. That code works ok in IE and FF, the actionListener is not fired in chrome and Opera, however if I click directly over the button works perfect in 4 browsers.

Thanks.

David