Creating a DIV Popup Warning - html

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>

Related

Why is my Bootstrap modal not working on my button?

I am using sublime text for my coding. I am working on a website contact page submission. I would like the button to be part of the contact page form.
Submit
<div class="modal" id="submitModal" tabindex="-1" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" dismiss="modal">×</button>
<h2 class="modal-title">Confirmation</h2>
</div>
<div class="modal-body">
<p>Your submission was successful!</p>
</div>
</div>
I would like the button to be responsive when clicked. However, it is responsive.

Include html code in modal from bootstrap

For school, I have to make my own website that shows some basic things to first years. So I got the idea, that I make a modal with Bootstrap. If you press the card, the modal will pop up.
Now, I want in the middle where 'CODE WHERE' is, to show the code for something. For example: let me just print or . But it won't let me, it will convert into HTML all the time and I don't want to convert it. I've looked a lot of pages, but I don't seem to find how. Anyone a solution?
Thank you very much.
<!-- Button trigger modal -->
<div style="cursor: pointer;" class="col-md-12" data-toggle="modal" data-target="#exampleModal">
<div class="card mb-4 shadow-sm">
<div class="card-body">
Text
</div>
</div>
</a>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Code</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<pre>
<code>
CODE HERE??
</code>
</pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close Modal</button>
</div>
</div>
</div>
First way is replacing < by < and > by > inside Your <code></code>.
Second way is make it change automatically in javascript:
var codeTags = document.querySelectorAll('code');
for (var i = 0; i < codeTags.length; i++) {
codeTags[i].innerText = codeTags[i].innerHTML;
}
Or easier in jQuery:
$('code').each(function(){
$(this).text($(this).html());
});

bootstrap modal wrong content

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.

How to get data data attribute values at modal box section?

I have modal box like this:
<!-- Modal FOR PLAYERS-->
<div class="modal fade" id="Info" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<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>
<h3 class="modal-title" id="myModalLabel">Player profile for</h3>
</div>
<div class="modal-body info-player">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<label>GOALK IN THIS SEASON :</label> 11
</div>
</div>
</div>
</div>
</div>
</div>
And i have added a Span Element where users can click on it to get the relevant data:
<span class="playerInfo" data-toggle="modal" data-target="#Info">Info</span>
but now i wan to have some "data-XYZ='VALUE'" attributes in my SPAN Element and I want to parse to my modal box, how could I do someting like this?
I only know the way with an jquery onclick handler, but i think is also another better way or what you think?
Thanks for your help or any hints...
thanks
You can make use of the bootstrap shown.bs.modal event
Occurs when the modal is fully shown (after CSS transitions have completed)
$('#Info').on('shown.bs.modal', function() {
$(".playerInfo").data("xyz"); //value
// use the above data however you want
})
HTML:
<span class="playerInfo" data-xyz="value" data-toggle="modal" data-target="#Info">Info</span>

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!