1

I am trying to load another page in a jquery ui modal

This is my Js File

function eventWindow(url) {
    getElementById("eventviewer").style.display="block";
    $("#eventviewer").load(url).dialog({
      modal:true,
      buttons: {
        Ok: function() {
          $(this).dialog("close");
        }
      }
    });
}

this the markup

    <!doctype html>
        <html>
        <head>
        <title><?php echo "Date:".$firstDayArray['month']." ".$firstDayArray['year'];?>
        </title>
        <link href="../css/main.css" rel="stylesheet" type="text/css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
        <script src="event.js" type="text/javascript"></script>
        </head>
        <body>
        .....
    <?php
        echo "<td class=\"days\"><a href=\"javascript:eventWindow('events.php?m=".$month."&d=".$dayArray["mday"]."&y=$year');\">".$dayArray["mday"]."</a><br/>".$event_title."</td>\n";
    ?>
<div id="eventviewer"></div>
        ......
        </body
        </html>

when i use window.open it works and opens in separate window.

But i am not able to open it in a jquery ui modal dialog.

3
  • SO You are trying to add html page in dialog Commented Jul 30, 2014 at 12:13
  • yes.. when the link is clicked event.php is called Commented Jul 30, 2014 at 12:26
  • Refer this stackoverflow.com/questions/15459107/… Commented Jul 30, 2014 at 12:30

1 Answer 1

0

There are multiple ways you can do this but I am not sure which one is the best practice. You can append an iFrame in the dialog container like this:

$("#dialog").append($("<iframe />").attr("src", "your link")).dialog({dialogoptions});

OR:

Working Fiddle

$(function () {
    var iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>');
    var dialog = $("<div></div>").append(iframe).appendTo("body").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: "auto",
        height: "auto",
        close: function () {
            iframe.attr("src", "");
        }
    });
    $(".thumb a").on("click", function (e) {
        e.preventDefault();
        var src = $(this).attr("href");
        var title = $(this).attr("data-title");
        var width = $(this).attr("data-width");
        var height = $(this).attr("data-height");
        iframe.attr({
            width: +width,
            height: +height,
            src: src
        });
        dialog.dialog("option", "title", title).dialog("open");
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.