Articles → JQUERY → Open Web Page In Modal Popup Using Jquery
Open Web Page In Modal Popup Using Jquery
Prerequisite
- Basics of asp.net.
- How to create a web application using Visual Studio?
- Basics about HTML controls like div.
- Basics about jQuery and jQuery UI.
- What are iframes?
Steps Involved
- Create an asp.net web application and include jQuery files in the header section
- Add anchor and a div tag
- Add iframe to div tag dynamically
- Output
Step 1. Create An Asp.Net Web Application And Include Jquery Files In The Header Section
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script><script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
Step 2. Add Anchor And A Div Tag
<a href="" onclick="return showDialog()">Show the Dialog</a><div id="divId" title="Dialog Title" />
Step 3. Add Iframe To Div Tag Dynamically
- Open div in a modal popup (by using dialog() method in jQuery’s ready function)
- Add iFrame programatically inside the div.
<script type="text/javascript">
function showDialog() {
$("#divId").html('<iframe id="modalIframeId" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />').dialog("open");
$("#modalIframeId").attr("src", "About.aspx");
return false;
}
$(document).ready(function() {
$("#divId").dialog({
autoOpen: false,
modal: true,
height: 500,
width: 500
});
});
</script>
Step 4: Output
Click to Enlarge