0

I have a GetValues function in JavaScript that the patameter result receives an HTML string this I would like to display and open a modal I was trying to do this with Iframe but if there is another easier way it is welcome.

thanks in advance

<div id="myModal" class="modal fade" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="myModalLabel">HTML Viewer</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
       <div class="modal-body">
       <iframe src="data:text/html;charset=utf-8,' + encodeURIComponent(result),"></iframe>
                </div>
            </div>
        </div>
    </div>
  function GetValues(result) {

var modal = document.getElementById("myModal");

    // Open the modal over everything
    modal.modal("show", { keyboard: false, backdrop: 'static' });

    // Add the HTML to the modal
    $("#myModal .modal-body").html(
      $('<iframe>', {
        src: 'data:text/html;charset=utf-8,' + encodeURIComponent(result),
      }));
}

Michaelweston
  • 149
  • 1
  • 11
  • 1
    Is there a specific reason you want to use an `iframe` for this? I'd argue that it's objectively the worst way to do... whatever it is you're trying to do. The purpose of the code isn't clear as there's a lot of it which has been removed. – Rory McCrossan Aug 08 '23 at 17:05
  • @RoryMcCrossan if you have another way without Iframe is fine too! – Michaelweston Aug 08 '23 at 17:07
  • 2
    I'd be happy to, but as my first comment mentioned, the code you provided is very unclear. For example - where does `result` come from? I'd suggest editing the question to include a full working example – Rory McCrossan Aug 08 '23 at 17:08
  • Yes, I understand, I don't want to add too many things so as not to fill up so many functions in the example, but this function GetValues receives the {result} parameter that contains an HTML string. The only thing I need to do is open a modal and display the HTML in the modal from {result} when I call GetValues. – Michaelweston Aug 08 '23 at 17:26
  • 1
    In which case simply set the `innerHTML` of the `.modal-body` div using the `result`: https://stackoverflow.com/a/2554171/519413 – Rory McCrossan Aug 08 '23 at 18:11

0 Answers0