I have a website running on Bootstrap, JQuery, HTML, CSS. I want to add a modal output on my website such that when a user clicks on a hyperlink a modal opens and prints content of a txt file. E.g. I have two text files which contains different details. And my website consists of sentence --> This is sam. This is his website. I want that when a user clicks on sam or website the respective text file is opened in a simple modal.
Asked
Active
Viewed 96 times
-1
-
link tou attached don't work... and show your code please – לבני מלכה Nov 14 '18 at 10:07
-
I have added the link for example. – Insta Nov 14 '18 at 10:08
-
@לבנימלכה Currently I have just added tag which opens the text file in a new tab. But I want to open the text file in a modal. So is there any way to do that? – Insta Nov 14 '18 at 10:10
-
Please read [ask] and create a [mcve] – Alon Eitan Nov 14 '18 at 10:10
-
use bootstrap model:https://getbootstrap.com/docs/4.0/components/modal/ – לבני מלכה Nov 14 '18 at 10:11
-
@לבנימלכה Its a good guide but it explains how to add a modal on a button. I want to add modal on a hyperlink – Insta Nov 14 '18 at 10:36
-
https://jsfiddle.net/19aqgmLy/ that what you mean? – לבני מלכה Nov 14 '18 at 10:39
-
@לבנימלכה Yes this is what I wanted – Insta Nov 14 '18 at 10:44
-
@לבנימלכה is there any way I could output the content of text file instead of modal body...? E.g. to view http://humanstxt.org/humans.txt in the modal? – Insta Nov 14 '18 at 10:47
-
see my edit in my answer – לבני מלכה Nov 14 '18 at 11:05
1 Answers
0
Use bootstrap-modal and instead use button
use a
:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<div class="container">
<a href="#" data-toggle="modal" data-target="#myModal">
Open modal from a
</a>
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
Modal body..
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
is there any way I could output the content of text file in that modal? E.g. to view http://humanstxt.org/humans.txt in the modal? Use:
$.get( "http://humanstxt.org/humans.txt", function( data ) {
$('.modal-body').html= data;
});
Or with .ajax
:
$(document).ready(function(){
$.ajax({url: "http://humanstxt.org/humans.txt", success: function(result){
$('.modal-body').html(result);
}});
});

לבני מלכה
- 15,925
- 2
- 23
- 47