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
* SafariASP.NETVisual Basic.NETChromeJavaScript

Avatar of undefined
Last Comment
Sudhanshum

8/22/2022 - Mon
Dorababu M

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?
Sudhanshum

ASKER
Nothing happening after removing isclose. Yes I am updating in database.
Dorababu M

Does that event fires? check in chrome console by putting break points
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Sudhanshum

ASKER
I am using web applications.
Dorababu M

So what we can debug the javascript in chrome console
Leonidas Dosas

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

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

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Sudhanshum

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Sudhanshum

ASKER
not got solution.