Link to home
Create AccountLog in
Avatar of Sudhanshum
Sudhanshum

asked on

OnbeforeUpload event not firing in chrome

I am using asp.net page, I have called following java script event:
  window.onbeforeunload = doUnload;
      function doUnload() {
                if (!isClose) {
             
              document.getElementById('<%=btnClose.ClientID %>').click();
          }
      }

So what I am trying to achieve is that if user close that page then I want to store some value in database,that's why I have fired button click event. This is working fine on IE11 but not working on chrome, Can you please tell me solutions to fix my problem asap.

Regards,
Sudhanshu
Avatar of Dorababu M
Dorababu M
Flag of India image

What was isClose value getting here is it false or true? Check by removing that condition and see whether you are able to perform as required. Also when you close the browser application will be stepped so what you are trying to insert to DB?
Avatar of Sudhanshum
Sudhanshum

ASKER

Nothing happening after removing isclose. Yes I am updating in database.
Does that event fires? check in chrome console by putting break points
I am using web applications.
So what we can debug the javascript in chrome console
Try this:
function doUnload() {
                if (!isClose) {
             
              document.getElementById('<%=btnClose.ClientID %>').click();
          }
      }

window.addEventListener('beforeunload',function(){
  doUnload();
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sudhanshum
Sudhanshum

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
not got solution.