Click here to Skip to main content
15,881,248 members
Articles / Web Development / HTML

Nested Modal Dialogs using Bootstrap

Rate me:
Please Sign up or sign in to vote.
4.60/5 (7 votes)
20 Feb 2019CPOL1 min read 31.9K   796   13   4
This project will show how to create nested modals.

Introduction

The goal of this project is to show how to create nested modals. Each modal is created from another page using an iframe. This approach lets you dynamically load as many modals as you need. Unzip bsModal.zip to a firtal directory and point your browser to Default.htm.

Most code is contained in BsModal.js file. This file will let you:

  1. Open a URL in a modal dialog using iFrame
  2. Create nested dialogs
  3. Show spinner while the page loads
  4. Open an external page in full screen dialog
  5. Move the modal dialog around the page

Image 1

The code uses three external libraries:

  1. jQuery (1.12.3)
  2. Bootstrap (3.3.6)
  3. Font-awesome (4.4.0)

Using the Code

To use this code, include BsModal.js file in the page that creates the first dialog. The key function is ShowModal(). It accepts the following parameters:

sUrl URL of the page to be loaded
iWidth width of the modal. Optional. When bank window width will be used
iHeight height of the modal. Optional. When bank window height will be used
oWin windows object of the calling modal page. Optional

From the main page (Default.htm) ShowModal() function can be used like this:

HTML
<input type="button" class="btn btn-info" value="Open Modal1.htm"
 onclick="ShowModal('Modal1.htm',300,430)">

From a dialog page, the ShowModal() function can be used like this:

HTML
<input type="button" class="btn btn-info" value="Open Modal2.htm"
 onclick="parent.ShowModal('Modal2.htm',300,350,window)">

A modal dialog can close by calling HideModal() function like:

HTML
<button type="button" class="btn btn-default" onclick='parent.HideModal()'>Cancel</button> 

History

  • 7th July, 2016: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Igor is a business intelligence consultant working in Tampa, Florida. He has a BS in Finance from University of South Carolina and Masters in Information Management System from University of South Florida. He also has following professional certifications: MCSD, MCDBA, MCAD.

Comments and Discussions

 
QuestionType 'Global.BootstrapModals.My.MySettings' is not defined. Pin
truword22-Feb-19 2:29
professionaltruword22-Feb-19 2:29 
AnswerRe: Type 'Global.BootstrapModals.My.MySettings' is not defined. Pin
truword22-Feb-19 4:33
professionaltruword22-Feb-19 4:33 
PraiseNice job Igor Pin
Bud Staniek21-Feb-19 10:37
Bud Staniek21-Feb-19 10:37 
QuestionWhere is the code? Pin
Andreas Kroll12-Jul-16 0:00
Andreas Kroll12-Jul-16 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.