user6514506
user6514506

Reputation:

how can I make a modal box to show a full php page?

I have a model box designed in jquery on one of my pages, I wonder if it is possible to make this modal show a full dynamic php page?

Upvotes: 1

Views: 2661

Answers (4)

Ravi Sharma
Ravi Sharma

Reputation: 1

Use jQuery load() like this,

jQuery part

<!-- Load jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<!-- A button on the page -->
<body>
    <button>Fetch Page</button>
</body>

<!--
1. Attach click event to 'button' with jQuery on()
2. Create a modal box dynamically with append()
3. Load 'the_dynamic_page.php' with jQuery load()
-->
<script>
$('body').on('click','button',function(){
    $('body').append("<div id='modal_box' style='border:1px solid #999;position:fixed;top:50%;left:45%;padding:0 0.75%;font-family:Calibri,Candara,Arial;'></div>");
    $('#modal_box').load('the_dynamic_page.php');
});
</script>

the_dynamic_page.php

This page could simply display a text like 'Im in a Modal Box!' or something from db.

Upvotes: 0

Karthik N
Karthik N

Reputation: 951

Include bootstrap.css and bootstrap.js

eg:,

<a data-toggle="modal" href="your_url content to show" data-target="#myModal">Click</a>

<div id="#myModal"></div>

Reference-http://getbootstrap.com/javascript/#modals

Upvotes: 0

Mickey
Mickey

Reputation: 534

Use iframe for modal box

<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">Trigger Modal in iFrame</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
          <iframe src="/user/dashboard" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>  
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

Iframe src will have your dynamic page.

Upvotes: 0

singe batteur
singe batteur

Reputation: 400

You can use the load() function, which is very easy to use, and well documented : http://api.jquery.com/load/ . it loads a page in the selected element, your modal's body for example, just calling a url.

Upvotes: 1

Related Questions