In our sharepoint item workflow we have users enter info into a form, then hit submit as usual. A manager does not want the users to have to do it again if they accidentally close the form, or fire drill or act of God destroys the laptop. So is there a way to submit when something accidentally closes the screen? I have a pending view and webpart that this could then go into. So if anything above happens someone else or the user can go back in later and start where they left off. My initial idea was just disable the x in the dialog, but that doesnt fix other scnarios. Maybe a capture close event? Any ideas are welcome. Im going to utilize the disable the x for now. Ill probably do both if anybody comes up with a solution.

Im working with sharepoint designer, and Infopath, security reason will not allow us visual studio.

  • 3
    How about disabling the form dialog box for that list and use the traditional form? No chance to accidentally close it then. – Paul Leigh Jan 30 '14 at 16:34
  • Can you describe how users are 'accidently' closing the modal form other than clicking the 'X' or 'Cancel' button? – tyshock Jan 30 '14 at 19:50
  • 1
    system crash. space debri crashing into the individual at thousands of miles an hour. User forgetting his backpack is on b4 second job as a clown and being shot out of a cannon. User resigns their position by throwing there laptop out a window. In other words system shutdown without recovery of windows. – RandallFlagg Jan 31 '14 at 16:53
  • 1
    Lol. Fair enough. If you REALLY need to handle scenarios to that level then the only viable option I can think of is to use something like jQuery and SPServices to dynamically update the object via AJAX on every field change. Is it worth it??? -- I don't know.....depends on your requirements/organization. – tyshock Jan 31 '14 at 17:10

You can hook to the window.onbeforeunload event and warn the user that she's about to leave the page.

window.onbeforeunload = confirmExit;
function confirmExit(){       
    return 'you have unsaved work. are you sure?';
  • 1
    That could work, but not for all scenarios. They are pretty adamant about this submitting to pending. I even thought about having the form submit to item based on each field being filled out after it goes to the next field the first is creating an item and inserting itself into pending, but that seems like a lot. this may be one of those situations that is we can do it this way but can't that way, but i don't want to leave a bad taste in their mouth about the limitations of sharepoint. – RandallFlagg Jan 30 '14 at 16:07
  • punctuation is not your forte, is it? ;) As I said in other occasions here, I strongly believe that we, as developers, should really learn to say no to unreasonable requests like this – MdMazzotti Jan 30 '14 at 16:16
  • 1
    if someone can't read it they can't be of much use. I could careless of punctuation when im in a hurry. Problem with throwing your "request is impossible" large corporations will eventually go with other means and lay sharepoint to the wayside, leaving sharepoint developers hungry, because the way the new generations are coming up they are being trained in specific drag and drop development. – RandallFlagg Jan 31 '14 at 16:47
  • I didn't say "your request is impossible". Which is a different thing. Btw, I'm not entirely sure I understand your conclusion. [edited] – MdMazzotti Jan 31 '14 at 16:51
  • surely not, but by rephrasing it in a proper and polite way, you certainly can. We're not brainless tools, are we? Anyhow, everyone has the vice president that they deserve :P – MdMazzotti Jan 31 '14 at 17:17

someone has come up with somthing of use!

window.onunload = window.onbeforeunload = (function(){

  var closedYet=false;

  return function(){
    if (closedYet) return;
    // do your thing here...


the above should help, you then need to write to a tempary list... this list will have the user ID or name and all the fields.... if they close than its saved to the list.... if they submit you need to remove from the list.

when the page loads you need to check the list for the user name... if it exists on the list than populate it.

so you need in javascript onload to check and populate, unload to save to list, submit check to see if it exists on list and if it does remove it.

to get you part of the way:


without doing it in visual studios that is the only way i could think of!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.