Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a URL in Bootstrap Modal dialog: On button click

I have to load a page (internal URL) in a modal window. I had been using window.showModalDialog(url, null, features) but this does not work properly on Safari,Chrome. So we decided to use Bootstrap's modal dialog instead. I'm unable to make this work. Any ideas what I could be doing wrong?

    //imports
    <script src="http://code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">


    //activate content as modal
      $(document).ready(function(){
            $('#test_modal').modal({

                });
    }

    .......
    .......

    $("#btnSubmit").click(function(){
     var url = constructRequestURL();
      $('#test_modal').modal(data-remote=url,data-show="true");
    });


    -----
    -----
    <div class="modal fade" id="test_modal">
</div>
like image 472
agentx Avatar asked Aug 13 '13 22:08

agentx


People also ask

How do I open URL in modal popup?

Use the window open() method to popup a window tab as a modal with a URL. Note: JavaScript already has the ShowModalDialog function but it does not work in all browsers.

How do you link a modal to a button?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.

How show modal on button click react?

Add The State and Methods Add a button inside the render block to trigger the modal. When the button is clicked, the isOpen state will be set to true. Now, to display the modal, all you need to do is pass the isOpen state value to the show prop of the <Modal /> component.

How show modal pop on button click in ASP NET MVC?

Step 1 : Start a new ASP.NET MVC Web application. Add a new controller called Home and in the Home controller, the Index method is available to you but there is not a view with it so add a view by right-clicking in Index action. Step 2 : In index. aspx add one HTML button to open our modal popup window like below.


1 Answers

If you're going to continue down the bootstrap path, you could take a look here: jsfiddle - remote URI in Bootstrap 2.3.2 modal

Note that the URL will need to be on the same domain (though you mentioned it is "internal") or your domain will need to be allowed by the remote site's Access-Control-Allow-Origin settings. So keep in mind that the fiddle demo can't actually load content from example.com.

<button type="button" class="btn" data-toggle="modal" data-target="#myModal" data-remote="http://example.com">Launch modal</button>

<div id="myModal" class="modal hide fade">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
       <!-- remote content will be inserted here via jQuery load() -->
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>

You don't need to write any custom JavaScript for this - Bootstrap will know what to do based on the data-attributes like data-remote="http://example.com/whatever" and data-target="#myModal" etc.

See the relevant section of the Bootstrap modal docs for more info...

Edit: It turns out that changing the remote URL dynamically isn't as easy as it could be. Hopefully this answer will help you further.

like image 164
codebyren Avatar answered Sep 23 '22 15:09

codebyren