0

i am working on a video uploading website where users are registering and uploading their video of unlimited size, the problem we are having that some users are not too smart that although we are showing them processing image and a message that we are processing your data, but still they don't find that video got uploaded or not and close the window before it get's uploaded, the average video size is around 500MB, so i thought about showing them an alert that your video is under processing when they try to close the window, i just want to know that is there any way that we can find that user is closing the browser or tab, i searched it but unfortunately couldn't find the solution, can anyone help me out please in this situation.

Thanks in advance.

Ravinder Singh
  • 3,113
  • 6
  • 30
  • 46
  • 3
    duplicate bruv: http://stackoverflow.com/questions/333665/javascript-to-get-an-alert-when-closing-the-browser-window :) look for api `unload` – Tats_innit Jun 02 '12 at 07:37

2 Answers2

1

Try this:

Javascript

<script language="JavaScript">
window.onbeforeunload = confirmclose;
function confirmclose(){
choice="Are you sure you want to leave?";
return choice;
}
</script>


Jquery

<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script src="jquery.confirm.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){
        function confirmclose() {
                return "Are you sure? you want to close";
        }
        window.onbeforeunload = confirmclose;
    });
Vinod
  • 4,672
  • 4
  • 19
  • 26
  • 1
    [MDN suggests](https://developer.mozilla.org/en/DOM/window.onbeforeunload) you both set the message as `e.returnValue` as well as returning it to ensure compatibility with all major browsers. See the example on that page. – Mattias Buelens Jun 02 '12 at 08:22
0
<script language="JavaScript">
window.onbeforeunload = WindowCloseHanlder;
function WindowCloseHanlder()
{
    window.alert('test');
}
</script>
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
sumit
  • 15,003
  • 12
  • 69
  • 110
  • what i am doing is i am submitting the form and this function in getting called on submit also because it gets called when window tries to load, – Ravinder Singh Jun 02 '12 at 07:50
  • i dont think there is a way to differentiate between refresh / close. –  Jun 02 '12 at 08:21