• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sleep Method in JavaScript

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my projects, my client wants a functionality to save the data in a table before the user is move to another page. So I thought calling window.onbeforeunload function will help me.

However I want this function to wait, until user selects his options. I tried is there any method is available to sleep the current function until the user triggers his options.

I tried with a while loop, but it really gone mad by hanging the browsers.

I feel it a real challenge to implement this. Any thoughts will be appreciated.

[ March 31, 2008: Message edited by: Mohammed Yousuff M N ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no concept of synchronous wait in the browsers. You didn't explain what you are trying to accomplish very clearly. Perhaps a better explanation would help?
[ March 31, 2008: Message edited by: Bear Bibeault ]
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example, if a user updates some data in a registration fields, and then clicks a new links with out saving the updated data (saving data happens using AJAX). So user shoud be notified before he is moving into another page.

The alert must custom alert, where a DIV will shown as a layer in the page and user will give his choice what to save the or not.

I believe I explain the scenario, please let me know if you have any comments.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try and fire off the Ajax request as a synch call, that might do the trick. There are downsides to synch calls, but this mihgt be your only optoion other than a nice discriptive message on the onbeforeunload explaining them that they need to go back and save.

Eric
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Eric for your updates. is there any call back functionality available in JavaScript ...

i think that may also help me to do this ..
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, I should have used spell check on my last post!

I am not sure what you are talking about.

My only suggestion was to try to set the asynch flag to true so you force the browser to wait until the response comes back before moving on. I am not sure if the browser will actually wait, but it might be a good thing to try out if you want to go that route. It is not hard to build a quick test script and see what happens.

Eric
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric if I was not wrong, Ajax request will help me to wait for some time in my current function, until the server timeout happens. But what if the user is not giving any values for a long time.

Will this technique will help me. Please advice if was wrong �

Thanks a lot for your comments.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Mohammed Yousuff M N",
Please check your private messages regarding an important administrative matter.
-Ben
 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any API in prototype which will help me to sleep the current function for few sec..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic