onbeforeunload event parameter and empty return value |
onbeforeunload event parameter and empty return value |
RainLover |
Jul 30 2014, 02:40 AM
Post
#1
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
Q1: I have seen the following code in most sources:
CODE window.onbeforeunload = function () { return 'You might lose your data!'; }; For example:
But on MDN the function has an extra parameter: (e). Why is that, what is the difference, and which is right? Q2: It seems that any browser has a default confirmation message that you cannot customize. Chrome, for example, displays: QUOTE Are you sure you want to leave this page? Can I content myself to this message and leave the return value empty: CODE return ''; |
Christian J |
Jul 30 2014, 05:18 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
But on MDN the function has an extra parameter: (e). Why is that, what is the difference, and which is right? Not sure, but I don't think that it has to be called exactly "e", and in the above case I think it's not even used for anything. See http://quirksmode.org/js/introevents.html#link10 (and further down that page) for usage examples. When using try/catch statements I recall it's mandatory for the catch statement to work: https://developer.mozilla.org/en-US/docs/We...nts/try...catch |
RainLover |
Jul 30 2014, 08:10 AM
Post
#3
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
|
pandy |
Jul 30 2014, 09:09 AM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Where do you find that "e"? I don't see it at MSDN. I know I need new glasses, but I really don't find it. It's not in the sample code, that I'm sure of.
|
Christian J |
Jul 30 2014, 01:16 PM
Post
#5
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
It's at MDN, not MSDN:
CODE window.onbeforeunload = function(e) { return 'Dialog text here.'; }; |
pandy |
Jul 30 2014, 01:30 PM
Post
#6
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Yeah, I figured as much, but where on the MSDN page? The only code sample I see is this.
CODE <!DOCTYPE html> <html> <head> <script> function closeIt() { return "Any string value here forces a dialog box to \n" + "appear before closing the window."; } window.onbeforeunload = closeIt; </script> </head> <body> <a href="http://www.microsoft.com">Click here to navigate to www.microsoft.com</a> </body> </html> |
Christian J |
Jul 30 2014, 02:21 PM
Post
#7
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
|
pandy |
Jul 30 2014, 02:47 PM
Post
#8
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
WHAT?
|
pandy |
Jul 30 2014, 02:48 PM
Post
#9
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Uh-oh!
|
pandy |
Jul 30 2014, 02:52 PM
Post
#10
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Don't you think it's just to show you can pass a parameter that way? It is odd though since they don't seem to do it for the other events I checked.
|
Christian J |
Jul 30 2014, 04:16 PM
Post
#11
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
Maybe someone just made a typo, can happen to the best of us.
|
Lo-Fi Version | Time is now: 25th April 2024 - 09:04 AM |