bootstrap modal wrong content - html

I am trying to make a Bootstrap modal, but right now when I open it up it inserts the html from the entire page and inserts it into my modal. I copied the sample modal straight from w3schools and I'm not using any JQuery to dynamically update it or anything.
When the modal is hidden the html shows me the correct structure: My navbar, content, then the hidden modal with the proper modal content. When I show the modal everything messes up. The same structure exists with the navbar, then content, then modal (not hidden as it should be). However, this time inside the modal is the html from the rest of the page repeated. A second modal along with the correct modal content is buried inside of the repeated html content, but it is also hidden. The result is that I see two versions of the body content, one in front of the other. When I hide the modal everything goes back to normal.
In other words this:
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Keeps getting changed to this:
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<meta></meta>
<title></title>
<script></script>
<div class="navbar"></div>
<div class="container"></div>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I should also point out that it does not duplicate tags such as head or body. It really doesn't make sense to me why the inside of the modal div is being changed at all when I want it to remain static. Any help is appreciated, thank you.

Related

bootstrap modal in background not usable

i use bootstrap on my website and i have modals which were working perfectly.
Since yesterday, my modals are not usable anymore. The grey background which should cover the area around the modal is now on the whole page. Thus, it's impossible to click on the modal or to use it. I have to reload the page manually.
Here is a screenshot :
I use the last version of Bootstrap (3.3.7). Even with the most basic modal exemple from official Bootstrap documentation it does the same :
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
I don't know where it could come from, since it's a bought template i didn't create myself.
Thank you in advance for any help

External Page Content Overflows out of Bootstrap Modal

I have the following Modal:
<a href="somepage.htm" data-toggle="modal" data-target="#extLinkModal">
<div class="modal fade" id="extLinkModal" tabindex="-1" role="dialog" aria-labelledby="extlinkModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog " role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="extLinkModalLabel"></h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
When I click the link to launch modal, the content of somepage.htm overflows out of the modal and there are no scroll bars on the modal?
How come this is happening?
Let's say you have 2 pages, index.htm and somepage.htm
you have modal in page index.htm and you want to show somepage.htm inside modal. Then
index.htm page code will be
<a href="somepage.htm" data-toggle="modal" data-target="#extLinkModal">
<div class="modal fade" id="extLinkModal" tabindex="-1" role="dialog" aria-labelledby="extlinkModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog " role="document">
<div class="modal-content">
//Here you can show the content from `somepage.htm`
</div>
</div>
</div>
and somepage.htm page content will be
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="extLinkModalLabel"></h4>
</div>
<div class="modal-body">
//Put the page content here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
This will resolve the issue somepage.htm overflows out of the modal and there are no scroll bars on the modal
Alternate Solution
OP asked in comments to load the remote page content into modal-body and above code example is default behavior of bootstrap v3+ where modal ignores the modal-body and always load the remote content into <div class="modal-content"> doesn't matter even if <div class="modal-body"> exist inside the <div class="modal-content">.
To get around this and make sure that the remote content load inside <div class="modal-body">
Use bootstrap modal events
Do not use href or remote in modal call button or link
So the modal call button or link will be
<a datalink="somepage.htm" data-toggle="modal" data-target="#extLinkModal" class="btn btn-primary">
where href changed to datalink or any word can be used but not href or remote otherwise modal will detect it as remote content and ignores the <div class="modal-body"> and load the content into <div class="modal-content">
Modal HTML
<div class="modal fade" id="extLinkModal" tabindex="-1" role="dialog" aria-labelledby="extlinkModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog " role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="extLinkModalLabel"></h4>
</div>
<div class="modal-body">
//Remote Page Content loads here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
and JS
<script>
$(document).ready(function() {
$("#extLinkModal").on("show.bs.modal", function(e) {
var link = $(e.relatedTarget);
$(this).find(".modal-body").load(link.attr("datalink"));
});
});
</script>
The content of somepage.htm overflows out of the modal because your somepage.htm page is not responsive, and your modal have some fixed height and width. So try to make your page responsive using bootstrap classes and some additional css if needed.
So making somepage.htm page content responsive will solve both problems of content overflows out of the modal as well as scroll bar.
Hope it will help you!

Creating a DIV Popup Warning

On this example: HTML / CSS Popup div on text click
How can I make this load on the index page when they visit the site the first time. I don't want a button to click, I want this load automatically; and then have a close button when they read the content on the popup. Thanks in advance.
Hi you can do this using bootstrap model popup
for this include bootstrap css and js files and use below code
Your Html Code
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" arialabelledby="myModalLabel" aria-hidden="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" id="myModalLabel">Intorduction</h4>
</div>
<div class="modal-body">
Body Text
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
then use this script
<script>
if (localStorage.getItem('showModal')!='yes')
{
localStorage.setItem('showModal','yes');
$('#myModal').modal('show');
}
</script>

Bootstrap 3.0 Modal Code in a separate file

I have a common modal that would be invoked from various places in different forms. I'm trying to write a common code for it in a separate file and invoke it. If code for Modal is included in the same file as button invoking it, it works fine. But if I place code for Modal form in a separate file, it doesn't open Modal form.
Here is the code of button invoking Modal form:
Edit
Here is the code of Modal Form in a different HTML file, "Modal.html":
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="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" id="myModalLabel">Club Search Result</h4>
</div>
<div class="modal-body">
<p id="dispMsg"> </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Search Again</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

Is there a way to pop up a modal window on top of another?

I'm making an application form that's on a modal and I made it so the user can upload their picture on the application form. So I have my thumbnail with a "upload picture" bubble inside it, and when I click it, a modal pops up. However the problem is when I click on "cancel" or "upload" on my "upload picture" modal, it closes both modal windows (application form and upload picture).
I'm using bootstrap and here's a snippet of my code:
<div class="modal fade in" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" style="display: block;">
<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" id="myModalLabel">Application Form</h4>
</div>
<!-- START OF MODAL BODY-->
<div class="modal-body">
<div class="col-sm-5">
<div class="thumbnail">
<div class="avatar">
<a href="#" class="thumbnail bottom-15" data-toggle="modal" data-target="#upload-avatar">
<img src="img/face1.jpg" alt="...">
</a>
<!-- Upload new avatar bubble -->
<div class="avatar-bubble">
<i class="fa fa-plus"></i> Upload new avatar
</div>
</div>
</div>
</div>
<!--Modal for uploading photo-->
<div class="modal fade" id="upload-avatar" tabindex="-1" role="dialog" aria-labelledby="upload-avatar-title" aria-hidden="true" style="display: none;">
<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" id="upload-avatar-title">Upload new avatar</h4>
</div>
<div class="modal-body">
<p>Please choose a file to upload. JPG, PNG, GIF only.</p>
<form role="form">
<div class="form-group">
<label for="file">File input</label>
<input type="file" id="file">
<p class="help-block">Files up to 5Mb only.</p>
</div>
<button type="button" class="hl-btn hl-btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="hl-btn hl-btn-green" data-dismiss="modal">Upload</button>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</div> <!-- END OF APPLICATION FORM MODAL BODY -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
Basically I put my second modal within my first modal.
Although the Bootstrap 3 docs say "Overlapping modals are not supported..", I think I found a workaround that works. You need to..
Make sure your 2nd modal's markup is outside the body of the 1st modal
Manually close the 2nd modal by using the Bootstrap modal toggle method in jQuery.
Change the z-index of the 2nd modal so that it appears over the first.
http://bootply.com/108243
Also, I changed your markup to remove the fade and `display:none'.
I've opened a modal from another modal. I call it 'modalception'. It sounds like you just need to make sure your events are targeting the correct modal.
I have overlapping modals, and they work as expected. Clicking the background of the second modal closes that modal only, not the one behind it.
Just set the z-index correctly. Be sure not to nest them, and it should work just fine. It is not "supported", but I do it all the time. A project I am currently working on stacks 3 on top of each other with no problems.
I am using Bootstrap v3.3.2 and jQuery 1.11.2.