Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

javascript - Trigger onbeforeunload event when there's still running ajax in the background

I'm sending ajax calls on my web application and I want to show message or trigger onbeforeunload if there are still ajax call that is not yet finished when they leave the page.

So far, what I'm doing is I declared a global variable to count the running ajax calls - before sending ajax call I increment the counter and once ajax call is finished I decrement. I need to trigger the onbeforeunload when the counter is more than 0 when they leave page, I don't know if it's possible?

The lowest browser version I'm supporting is Firefox 45.0.2 Javascript only please.

question from:https://stackoverflow.com/questions/65937543/trigger-onbeforeunload-event-when-theres-still-running-ajax-in-the-background

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...