Thank you so much for your response T.J. I emailed my work friends the same question. It hit me yesterday. My friend was like why don't you create your own window. Then I realized that in showing and hiding divs we're just manipulating the dom and that like you said the browser doesn't know to stop and wait for the user click. So I tried a bunch of stuff:
"Any other window libraries I use, utilize displaying and not displaying divs. Therefore when an unload occurs the browser does not wait for the window to be rendered before moving on. Well, if I execute a loop after displaying the window so the window can have time to be rendered, most browsers give an unsecure javascript popup. If I set a recursive timeout I eliminate the popup, but the “moving to the next page” supercedes the “oncoming timeout” so that doesn’t work either." Let me know if you can think of any other scenario I may not have tried. They allowed me to use the confirm at work. But I wish there was a way to do it. Thanks so much for your response. You seem really smart. Radha On Sun, Mar 8, 2009 at 4:47 AM, T.J. Crowder <[email protected]> wrote: > > Hi, > > The reason that using it with the unload doesn't work is that it > doesn't stop execution at the point it's shown the way alert and > confirm do. As far as I know, only built-in things like alert and > confirm can do that. Consequently, you show the dialog, but then the > browser continues with what it was doing -- which is to move away from > the page. > > Your option 3 of opening another window with all the data and your > "save?" question is unlikely to be successful; opening a window from > the onload event is a classic means of trying to trap the user into > looking at multiple adverts and you're likely to run afoul of ad- > blockers. And that's just as well, it's not a great user experience. > > Your option 4 is not possible. For links within your page that take > the user elsewhere, you could do it. But if the user is just typing > in a new URL in the address bar, selecting a favorite, hitting their > "home" button, etc., your page is not -- and never will be -- told > what page they're going to. > > This is a common problem and I wouldn't be surprised if someday > browsers start providing better mechanisms around this. Frankly, > though, with the current standards I doubt you're going to find a > solution to this that provides a better user experience than the built- > in confirm windoww, which does after all allow you to provide a > message to show and does provide reasonable options if you phrase your > question right. So I'd recommend: > > 1. Live with the confirm window. > > or > > 2. Redesign your app such that users' changes are automatically saved > to a "draft" area as they're made, so that when they come back, you > can let them pick up where they left off (keeping the changes, > continuing with making changes, or discarding them) -- something akin > to GMail's (and others') handling of draft email messages. And as > with GMail's draft messages, there will always be a brief period > between a change being made and your saving a draft of it, so you'll > probably need to use a confirm in that interval (as GMail does). > > HTH, > -- > T.J. Crowder > tj / crowder software / com > Independent Software Engineer, consulting services available > > > On Mar 7, 3:45 pm, "[email protected]" <[email protected]> > wrote: > > I have requirements to code something that I need some help with. I > > am encountering the following issue: I need to display a window right > > before someone leaves the page they are on. Basically prompt them to > > save their changes or continue on to the next page. On the save I > > execute an AJAX request to Save and then they go on to the next page. > > Well I can do this easily using the regular javascript confirm object: > > <body onunload="var x=confirm("save changes");if(x) ajxcalltosave();"> > > > > However I need to do this using the prototype window. As I need to > > override the button choices to be "yes, save" or "no, don't". (which > > to my knowledge you cannot do with confirm) > > During the unload event-- When I instantiate a Dialog.confirm window > > via prototype's libraries the window shows up for a split second and > > the user gets redirected to the next page. I want to make the > > prototype window stay before moving on to the next page. That is the > > issue. I have used it before and can display the window and it > > behaves properly on every other event other than unload, and I don't > > understand why. I'm sure if I step through the code enough times I > > should hopefully find some clue as to its behavior. But haven't found > > any so far. > > > > I could open another window referring to a different page with the > > question and buttons, in which case the parent page would already move > > on and I'd have to pass all the information to execute the save as > > parameters to the request displayed in the new window. That would be > > kind of cloojy. > > > > If there is some way I could abort the unload or redirect back to the > > same page then show the Dialog.confirm window that would work but I > > would need to know where the user initially intended on leaving to so > > that I could redirect them there after the save. > > > > RECAP > > Option 1: Override confirm's button choices. CON: Not possible as > > per my knowledge > > Option 2: Make the prototype window not disappear before moving on to > > the next page. CON: I don't know how > > Option 3: Open another window CON: Not pretty, the parent page moves > > on before the save occurs, would not appease requirements > > Option 4: Abort the unload, stay on the same page CON: Need to know > > where the user meant to go so they could be redirected back there > > later > > > > Thank you for reading this. If you can provide some insight to my > > issue, I'd really appreciate it. (I really would like to be able to > > execute option 2.) > > > > :-) > > radha > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
