1

In Jquery i invoke the method $(window).unload(). it is used for when i closing the browser window i'm return the some values.this function is working fine in I.E. but it is not working in other browsers.

$(window).unload() function is for i.e ? Anybody can help me. thanks in advance.

ELAYARAJA
  • 521
  • 3
  • 10
  • 23
  • I believe it is window.onunload [widthout an S] and it is a core javascript – CME64 Jun 25 '13 at 07:36
  • What exactly are you returning? onunload should work same everywhere – Entity Black Jun 25 '13 at 07:40
  • @CME64, sorry you are right. i just edited my question. – ELAYARAJA Jun 25 '13 at 07:40
  • here is my code: $(window).unload(function() { if(event.clientY < 0) { returnValue=2; } }); – ELAYARAJA Jun 25 '13 at 07:42
  • what are you trying to do ? and where are you catching that event? and why do you want to assign a value when the user is leaving the page? it will be dropped anyways – CME64 Jun 25 '13 at 07:46
  • i'm open the modal window, in this window i have two options to close the window one is cancel button and another one is browser close button. if i closing the window by cancel button means whole function is ended, if i closing by browser window means just browser options. in this place only i returning the values. – ELAYARAJA Jun 25 '13 at 07:51
  • I don't get you, can you elaborate on a clear story line? – CME64 Jun 25 '13 at 07:55
  • 1
    @Elayaraja You can try to use (native) `onbeforeunload` instead of `onunload`. Also the implementation of `showModalDialog()` in Chrome is so buggy, that it's rather useless. – Teemu Jun 25 '13 at 07:57
  • @Teemu i think it is not right solution for me . can show me any example. ? – ELAYARAJA Jun 25 '13 at 08:05
  • @Elayaraja Please check [main window](http://jsfiddle.net/7Rybx/2/) and [dialog](http://jsfiddle.net/fP86T/4/) at jsFiddle. Dialogs don't seem to work in a fiddle, but you can copy codes and try it yourself. Notice, that probably these snippets are not working in Chrome, but work well in IE and FF. Actually it looks like also `onunload` would work as well in both browsers... – Teemu Jun 25 '13 at 09:17
  • 1
    Hmm... one more thing, `onunload` event has no property named `clientY`, it's only mouseevents having that. – Teemu Jun 25 '13 at 09:24
  • No, it gets null value while i closing the window even in firefox. – ELAYARAJA Jun 25 '13 at 09:47
  • @Elayaraja Yes, in the fiddle it does (also in IE). You need to create a local copy from the snippets, modal dialog is not working in jsFiddle when using this way. – Teemu Jun 25 '13 at 10:00

1 Answers1

3
<script>
window.onbeforeunload = function() {
    return "Are you sure?";
 };
</script>

or

$(window).on('beforeunload', function() {
    return 'Your own message goes here...';
});

in chorme there are several blocked method on onbeforeunload like alert..
A chorme example of the debugging console for an alert:

Blocked alert('My Window is reloading') during beforeunload.

ref1 ref2

Community
  • 1
  • 1