简体   繁体   中英

Inhibit modal window from closing on background click

I am using Twitter Bootstrap, and I am creating a modal with a shaded background. I want the modal to stay up until I click close, and when someone clicks the background it will not close.

I can't find a solution. I know how to do with a backdrop, but then there is no background.

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

// by default backdrop: true so just set it to static.

In the modal, there is a data attribute called backdrop. You can set it to true or false:

data-backdrop="false"

You can also specify it as static if you want the backdrop but it should not close on clicking.

Another hack is to disable the backdrop and have your own backdrop with the following properties so that the modal doesn't close on clicking. CSS for the backdrop:

{
position:relative;
height:100%;
width:100%;
background:#000000;
opacity:0.2;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM