Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:26:48+00:00 2026-06-14T14:26:48+00:00

I am using Twitter Bootstrap modals, with the default options where you can click

  • 0

I am using Twitter Bootstrap modals, with the default options where you can click the backdrop or press [Esc] to close the modal.

However, when I initiate an ajax operation in the modal I want to disable the modal from being closed in any way. So I disable buttons and hide the modal’s close button but I can’t figure out how to disable the backdrop and the [Esc] key.

I tried:

$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
});

But this doesn’t seem to work on the fly.

I will also need to re-enable the backdrop and keyboard once the ajax operation is finished.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:26:50+00:00Added an answer on June 14, 2026 at 2:26 pm

    Note: This solution is targeting twitter bootstrap 2.x! See this answer (just below) for differences according to bootstrap 3.


    Extending bootstrap modal functionality without modifying original source.

    Thanks to @David and his suggestion at How to Extend Twitter Bootstrap Plugin I finally got it to work. It is a slightly modified version of his solution with modal “lock” added. I post it as a additional answer since I think it may could be a starting point for others that like me have struggled hard with this issue.

    // save the original function object
    var _superModal = $.fn.modal;
    
    // add locked as a new option
    $.extend( _superModal.defaults, {
        locked: false
    });
    
    // create a new constructor
    var Modal = function(element, options) {
        _superModal.Constructor.apply( this, arguments )
    }
    
    // extend prototype and add a super function
    Modal.prototype = $.extend({}, _superModal.Constructor.prototype, {
        constructor: Modal
    
        , _super: function() {
            var args = $.makeArray(arguments)
            // call bootstrap core
            _superModal.Constructor.prototype[args.shift()].apply(this, args)
        }
    
        , lock : function() {
            this.options.locked = true
        }
    
        , unlock : function() {
            this.options.locked = false
        }
    
        , hide: function() {
            if (this.options.locked) return
            this._super('hide')
        }
    });
    
    // override the old initialization with the new constructor
    $.fn.modal = $.extend(function(option) {
        var args = $.makeArray(arguments),
        option = args.shift()
    
        // this is executed everytime element.modal() is called
        return this.each(function() {
            var $this = $(this)
            var data = $this.data('modal'),
                options = $.extend({}, _superModal.defaults, $this.data(), typeof option == 'object' && option)
    
            if (!data) {
                $this.data('modal', (data = new Modal(this, options)))
            }
            if (typeof option == 'string') {
                data[option].apply( data, args )
            }
        });
    }, $.fn.modal);
    

    With this technique it should not be nessecary to alter bootstrap.js, and the same functionality can more easily be shared among bootstrap projects. This method should be applicable to all the other bootstrap plugins. Have so far only tried with button though, but I cant se why it shouldnt.

    see working fiddle -> http://jsfiddle.net/Sz7ZS/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a modal window using Twitter Bootstrap. The default behavior is if
I was looking to using the Twitter Bootstrap Modal windows as a partial view.
I'm asking about using a Twitter Bootstrap modal window with a Rails form helper
I found this link Link to another page using Twitter Bootstrap jquery modal in
I am using Twitter Bootstrap, (CSS and JS). The problem comes from the Modal
I am using the modal component within the Twitter Bootstrap package. This modal opens
I am using Twitter bootstrap modals To load data from a table. Here is
I'm using twitter bootstrap modal dialog. And it works fine while only opening it
I am using the Twitter's Bootstrap plugin bootstrap-modal . It works well except for
I'm using Twitter Bootstrap modal featurs and loading data from remote locations. I'm providing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.