Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5: Load Remote Content in Modal via URL #36086

Closed
abdulrazakshaikh opened this issue Mar 30, 2022 · 2 comments
Closed

Bootstrap 5: Load Remote Content in Modal via URL #36086

abdulrazakshaikh opened this issue Mar 30, 2022 · 2 comments

Comments

@abdulrazakshaikh
Copy link

abdulrazakshaikh commented Mar 30, 2022

I m trying to add a modal content via url using bootstrap 5 no jquery.

I have achieved in previous version of bootstrap using jquery with the below code.
`$('#mySmallModal').on('show.bs.modal', function (e) {
var link = $(e.relatedTarget);
var modal = $(this);
modal.find('.modal-content').load(link.attr("href"));

});`

@GeoSot
Copy link
Member

GeoSot commented Mar 31, 2022

const modal = document.querySelector('#mySmallModal');

modal.on('show.bs.modal', function (e) {
   const  link = e.relatedTarget.getAttribute('href');

   fetch(link).then(res => res.text()).then(html => {
     modal.querySelector('.modal-content').innerHtml = html
   });
});

I suppose something like this, could do the job 😉

@GeoSot GeoSot closed this as completed Mar 31, 2022
@abdulrazakshaikh
Copy link
Author

abdulrazakshaikh commented Apr 6, 2022

@GeoSot This Works for me

const modal = document.getElementById('exampleModal')
modal.addEventListener('show.bs.modal', function (event) {
    
  // event.preventDefault();
  const link = event.relatedTarget.getAttribute('href');
  const modalData = document.querySelector('.modal-data');

  fetch(link).then(res => res.text()).then(html => {
    modalData.innerHTML = html; 
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants