We run a file upload service. While files are being uploaded users need to stay on the page, so we use window.onbeforeunload:

window.onbeforeunload = function() { return 'You still have files uploading...'; };

When the user tries to reload the page, close the page, or go to a new URL the browser warns him and he gets a chance to stay on the page.

This works, but we have found a strange behavior in Chrome.

When you try to go to the URL of a site you often visit it won't show the user the popup, but just quickly go to the requested page. In my case I could get this to work with reddit.com, facebook.com, but not dog.com.

I think it may have something to do with prerendering, or some other optimization that Chrome has, which makes it ignore onbeforeunload.

You can try it out by going to http://ge.tt and start a file upload. Then go to a different URL, and choose a website you often visit. Chrome should (incorrectly) let you do it.

Does anyone know what to do about this? Is onbeforeunload not something we should use any longer?