4

Say I display a div through using jQuery, but I want the rest of the window (everything except that div) be unaccessible for user - so all the controls are disabled and the user can only do something with the controls in that special div?

5
  • demos are here jquery.malsup.com/block/#demos Commented Dec 7, 2010 at 19:46
  • as i said simple fix can be z-index/// Commented Dec 7, 2010 at 19:47
  • I think you are looking for an expose effect. Commented Dec 7, 2010 at 19:48
  • I used fancybox. here it is fancybox.net Commented Dec 7, 2010 at 20:18
  • @everyone - thank you for all the answers, all the samples are great. So giving +1 to everyone! Commented Dec 8, 2010 at 18:26

4 Answers 4

4

You can build a modal dialog from your <div> element:

$("#yourDivID").dialog({ modal: true });
Sign up to request clarification or add additional context in comments.

3 Comments

Learn something new every hour on SO :)
I get the Object does not support this property or method.
@Max, the jQuery UI framework defines the dialog() method (among others).
2

Please use jquery bock UI plugin

http://jquery.malsup.com/block/

for a simple fix , if your z-index of popup is greater than all the elements behind , you cannot touch the items behind

give z-index like 1000 or so

Comments

1

Do a search for "jquery lightbox" and you will find what you are after, or use the jquery modal dialog as mentioned in another answer.

I like lightboxes as they overlay the page with an opacity mask, clearly showing the controls are disabled/not accessible.

Comments

1

Rather than using full blown plugins for something that is so simple:

Use a second div, whose css position is fixed and whose width and height is equal to the window.innerHeight & window.innerWidth properties respectively. Set the z-index to something large, but less than the z-index of the model dialog your showing.

$('<div />').css({
    position: 'fixed',
    left: 0,
    top: 0,
    width: window.innerWidth,
    height: window.innerHeight,
    'z-index': 1000
});

As mentioned in the comments however, this does not stop the users tabbing to the hidden fields; to do that, you can bind an event to capture the tab press, and cancel it:

$(document).bind('keydown', function (event) {
    if (event.which === 9 && !$(event.target).closest('.model').length) {
        event.preventDefault();
    }
});

To give you the ability to add/ remove the event handler at will, it will be easier to do it like so:

function stopTab(event) {
    if (event.which === 9 && !$(event.target).closest('.model').length) {
        event.preventDefault();
    }
}

$(document).bind('keydown', stopTab); // to add
$(document).unbind('keydown', stopTab); // to remove

Your modal dialog must have a class of modal for this to work (or simply alter the selector).

3 Comments

yeah you are right , thats what i mentioned too , its quick and easy too.
this doesnt prevent the user from tabbing over behind the div and using the controls via keyboard
@mkoryak , is it ,,thanks for telling us new thing , then its better to use dialog or block UI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.