Possible Duplicate:
Div as modal – javascript
Is there a way to somehow lock a page in Javascript until a function call is complete? What I have in mind is like a semi-transparent grey cover that prevents any other user actions such as mouse-overs or button clicks until the current request is done processing. The look-and-feel doesn’t matter quite as much as the functionality, though.
I haven’t been able to find anything that does this. Most “solutions” to this problem simply say to wait to load the other HTML elements until you’re done with whatever processing you’re performing, but in this particular circumstance, all the options are already present on the screen. I want to be able to prevent the user from performing another action from the page until the current request is complete.
I tend to use a simple
divand somejavascriptto do this sort of thing.So for example, in your page create a
div, which will function as your grey-out.Then style it like so:
Then when your process is about to begin you can call (to show it):
And once its done you can hide it again by:
When you do show it, you may want to set the
overflowof yourbodytohidden, then back toautotoo, this will prevent the user scrolling and only seeing partial blackout.Now I normally use
jqueryfor theshowandhidethough am pretty sure thejavascriptabove is correct..Update:
To keep everything much tidier, as Chad mentions, you’re better off putting all styling into CSS. I.E.
and remove the style from the
DIV. I.E