Application.CancelQuit on webGL

Hello all,

I trying to cancel the quit on webGL but the function isn’t seems to works.

public void OnApplicationQuit() {
Application.CancelQuit();
}

can you help me with this?

From the documentation:

Does nothing in web player, editor, or iphone…

1 Like

Is there any other solution?
I try to use window.onbeforeunload in javascript code but it seem’s to be override by Unity…

Applications usually are quitting in the browser because they closed the browser window.

What are you trying to do? STOP closing the browser window? No… you can’t do that.

1 Like

I want to warn to player that he hasn’t save data before leaving. So yes i want to STOP closing the browser window.

The only way I could think of doing this is calling an external function in the browser, and have a javascript function out there that blocks closing the browser window (a popup window?). Do note though if they have settings configured so that it doesn’t get blocked by such methods, it won’t get blocked.

But internally from Unity, no, not that I know of. It’s the entire point of browser’s and their security levels and sandboxes to keep software from inconveniencing them in such a manner. Such behaviours are often viewed as being invasive, if not malicious.

A lot of Web site block the closing so it’s not suppose to be malicious (if it’s just one time). The function to prevent a windows to be close in javascript is :

window.onbeforeunload = function(){
      return "Nice message";
}

but Unity seems to overwrite this method. The only technique i found is to overwrite the method every 2 sec. It’s very strange and dirty but it’s work. So i’m looking for a better solution.

Just because a lot of sites do it doesn’t mean that there aren’t people who consider it invasive and/or malicious… and functionality exists in most all browsers to block a site from being able to do so.

But hey, you seem to know more than I do on the matter, you already knew how to block closing the browser… so why’d you even ask the question in the first place?

because the correct solution is block by unity in some way. So i’d like to have a better solution (more clean)

  1. why is that the correct solution?

  2. that solution isn’t there, as the documentation states.

Unity isn’t the browser, the browser gives you access to that, so use the browser to do it. That why we have an interface in unity to communicate with the browser.

1 Like