Building modals with Bootstrap

Currently, my website is built using Bootstrap, JQuery, HTML, and CSS. I am looking to enhance the user experience by incorporating a modal output feature. The idea is that when a user clicks on a specific hyperlink, a modal window will open displaying the content of a corresponding txt file. For example, let's say I have two text files with different information. Within the content of my website, there are sentences like "This is sam. This is his website." What I want to achieve is that when a user clicks on "sam" or "website," the respective text file associated with that term opens up in a simple modal window.

Answer №1

Utilize bootstrap-modal and replace the button with 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">&times;</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>
Edit to you comment

Is there a way to display the content of a text file in that modal? For example, viewing in the modal? Use:

$.get( "http://humanstxt.org/humans.txt", function( data ) {
  $('.modal-body').html= data;
});

Alternatively, with .ajax:

$(document).ready(function(){
        $.ajax({url: "http://humanstxt.org/humans.txt", success: function(result){
            $('.modal-body').html(result);
        }});
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Button Click Not Allowing Webpage Scroll

I am currently in the process of developing a website that aims to incorporate a significant amount of motion and interactivity. The concept I have devised involves a scenario where clicking on a button from the "main menu" will trigger a horizontal and ve ...

Laravel error message for unresolved symbolic link

Previously, I had developed a form for uploading profile pictures using the code snippet below, $image = $request->file('avatar'); $pass = Hash::make($request->password); if($image!=null){ $avatar_na ...

Are the menubar menus positioned beneath a different div element?

Currently facing an issue with an HTML Menubar where the menus are appearing below another div, and not getting displayed as expected: ...

If the user inputs any text, Jquery will respond accordingly; otherwise,

I have a text field that is populated from a database, but if a user decides to change the value, I need to use that new value in a calculation. $('#ecost input.ecost').keyup(function(){ if (!isNaN(this.value) && this.value.length != ...

Input fields that are dynamically generated do not respond to changes made using .click and .blur methods in jQuery CSS

I'm experiencing an issue with a HTML form where a new input field is generated when a button is clicked, but the dynamically created field is not styled properly. Below is the HTML form code: <form id="form"> <input type="text" id="ent ...

using mixins with styled-components

I have encountered a challenge while attempting to pass a mixin from Material UI to a styled-component. The problem lies in finding a way to transfer the mixin value to the styled-component without having to assign it to a css property. Unfortunately, dire ...

Creating objects that are a fraction of another's width

My goal is to create 3 responsive divs that fill the width of the window and adjust their width based on the window dimensions. However, I'm facing an issue with JavaScript where it seems to be miscalculating the window width, causing the objects to o ...

How to efficiently toggle between multiple classes on a div element using Jquery

I have three distinct divs: If I click on the next or previous div, I would like to remove the blue background from the <h4>. When the <h4> has a blue background (as mentioned above), I want to add a specific class to the <i class="fa fa-l ...

Use jquery to rotate the div and animate it to move upwards

Hey everyone! I'm having an issue with rotating and moving an image inside a div element. I've tried some code to make it work, but nothing seems to be happening. Any tips or suggestions on how to tackle this problem would be greatly appreciated. ...

attempting to eliminate on-screen buttons by hovering over the video

Is there a way to make my video play on loop like a GIF without the controls ever showing? I want it to have a seamless playback experience. Any ideas would be appreciated. P.s. Don't worry about any StackOverflow errors when running the snippet. Than ...

How come my HTML form keeps refreshing instead of displaying an alert after submission, even though I've included onsubmit="return false"? Additionally, it seems to be throwing an error

Why is this basic HTML and JavaScript code not functioning properly? Instead of alerting once the form is submitted, it refreshes the page and throws an error. It has also been reported to sometimes throw a CORS error when using 'module' as scri ...

"What is the best way to include additional fields within a popover in an AngularJS application

This is my code for implementing a popover using AngularJS. I am trying to figure out how to add custom styling to the popover HTML, but I am having trouble binding elements in that part of the code. <!DOCTYPE html> <html> <head> <l ...

Managing the vertical positioning of grid items: tips and tricks

Is there a way to make the hexagons in my grid responsive to the layout, so that their height and width remain fixed relative to their container? Currently, they are overflowing from the grid container as shown in this jsfiddle: https://jsfiddle.net/gv5wc1 ...

Effortless integration of jQuery with Google Maps autocomplete feature

I've successfully implemented Google Maps Autocomplete on multiple input tags like the one below: <input class="controls pac-input" id="pac-input" type="text" onfocus="geolocate()" placeholder="Type custom address" /> To enable Google Maps au ...

Unable to utilize the rupee font within a select element on Chrome and IE8 browsers

Issues with displaying rupee font in select element on Chrome and IE8 I have implemented WebRupee for showing the Indian currency symbol. The font appears correctly when used within a <p> tag, but when placed inside a select option element, it only ...

Animate a div once the parent section becomes visible while scrolling

I previously had this function working, but it seems that I have somehow messed it up in the process. My current setup includes a scroll hijack feature that navigates users to a new section or card each time they scroll. The script adds a visible class w ...

Is it possible to display this code through printing rather than using an onclick event?

I have a puzzle website in the works where users select a puzzle to solve. I am looking for a way to display the puzzles directly on the website instead of using pop-up boxes. I am proficient in various coding languages, so any solution will work for me. ...

Pass a variety of data points to PHP using Ajax requests

I am facing a challenge with passing multiple parameters during Ajax calls. The code works perfectly when I only pass one parameter. Here is the code snippet for the Ajax call: $.ajax({ type: "POST", url: "dataCartas.php", ...

Firefox users may notice that the pop-up video player appears in unusual locations on their screen

I'm encountering an issue with a pop-up video player that is triggered by an "onClick" event in HTML elements. The problem arises when there are multiple video players on the same page - in Firefox, the first video loads at the bottom of the page, req ...

What is the best way to position a Radio group next to a TextField in Material UI

I've been through the documentation, but I'm struggling to understand how styling works in Material UI. Currently, I have a radio-group component set up like this: import React from 'react' import Radio from '@material-ui/core/Rad ...