OnbeforeUpload event not firing in chrome

Sudhanshum
Sudhanshum used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dorababu MSenior Software Engineer
Distinguished Expert 2018

Commented:
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?

Author

Commented:
Nothing happening after removing isclose. Yes I am updating in database.
Dorababu MSenior Software Engineer
Distinguished Expert 2018

Commented:
Does that event fires? check in chrome console by putting break points
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I am using web applications.
Dorababu MSenior Software Engineer
Distinguished Expert 2018

Commented:
So what we can debug the javascript in chrome console
Distinguished Expert 2017

Commented:
Try this:
function doUnload() {
                if (!isClose) {
             
              document.getElementById('<%=btnClose.ClientID %>').click();
          }
      }

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

Open in new window

Hi Leonidas Dosas, Thanks for reply, I tried this also but not working in chrome. is there any way to find open tabs?

Author

Commented:
not got solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial