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
SudhanshumAsked:
Who is Participating?
 
SudhanshumConnect With a Mentor Author Commented:
Hi Leonidas Dosas, Thanks for reply, I tried this also but not working in chrome. is there any way to find open tabs?
0
 
Dorababu MSenior Software EngineerCommented:
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?
0
 
SudhanshumAuthor Commented:
Nothing happening after removing isclose. Yes I am updating in database.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Dorababu MSenior Software EngineerCommented:
Does that event fires? check in chrome console by putting break points
0
 
SudhanshumAuthor Commented:
I am using web applications.
0
 
Dorababu MSenior Software EngineerCommented:
So what we can debug the javascript in chrome console
0
 
Leonidas DosasCommented:
Try this:
function doUnload() {
                if (!isClose) {
             
              document.getElementById('<%=btnClose.ClientID %>').click();
          }
      }

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

Open in new window

0
 
SudhanshumAuthor Commented:
not got solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.