Results 1 to 2 of 2

Thread: How to open remote content in modal via URL parameters

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    2

    How to open remote content in modal via URL parameters

    Hi all,

    I am using a modal in Bootstrap 4 to show remote content from different HTML files.

    For this purpose I found some JS on stackoverflow:

    Code:
    <script>
    $('body').on('click', '[data-toggle="modal"]', function(){
    $($(this).data("target")+' .modal-body').load($(this).data("remote"));
    });  
    </script>
    This works fine with links in the main page - but I need to access those remote filled modals directly via the URL.

    Example: I type something like index.php?id=remote.html#mymodal to open my site with an active modal filled by remote.html.

    So I would need some piece of script that examines the incoming URL request for certain parameters and then open the modal with the requested remote content on pageload.

    If someone can help me out, I'd be very happy!

    Thanks a lot and best regards,
    Alex

  2. #2
    Junior Member
    Join Date
    Feb 2018
    Posts
    2
    Via trial&error I found some sort of solution:

    Code:
    <script>
          $(document).ready(function () {
            if (window.location.href.indexOf("regex") > -1) {
              var url = "regex.html";
              $('.modal-body').load(url,function(result){
              $('#myModal').modal({show:true});
              });
            }
          });
    </script>
    It basically works by opening "www.domain.tld?regex", but the performance is low. Any ideas for improvement?

    Thanks a lot & best regards
    Alex

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •