Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Example of Setting Bootstrap 3 Modal's keyboard Option via Data Attribute</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .bs-example{ margin: 20px; } </style> </head> <body> <div class="bs-example"> <p><strong>Note:</strong> Click the following buttons to show modals with different <code>keyboard</code> option setting.</p> <!-- Button HTML (to Trigger Modal) --> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#escHideEnabled">Modal (data-keyboard="true")</button> <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#escHideDisabled">Modal (data-keyboard="false")</button> <!-- Modal HTML --> <div id="escHideEnabled" class="modal fade" data-keyboard="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Sample Modal</h4> </div> <div class="modal-body"> <p>This Bootstrap modal cannot be closed with the escape key on the keyboard.</p> <p class="text-info"><small><strong>Note:</strong> Press Tab key on the keyboard to enter inside the modal window after that press the Esc key. Since keyboard option is set to <code>true</code> that means modal hide on the press of escape key.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK</button> </div> </div> </div> </div> <!-- Modal HTML --> <div id="escHideDisabled" class="modal fade" data-keyboard="false"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Sample Modal</h4> </div> <div class="modal-body"> <p>This Bootstrap modal cannot be closed with the escape key on the keyboard.</p> <p class="text-info"><small><strong>Note:</strong> Press Tab key on the keyboard to enter inside the modal window after that press the Esc key. Since keyboard option is set to <code>false</code> that means modal will not hide on the press of escape key.</small></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">OK</button> </div> </div> </div> </div> </div> </body> </html>