Paul
Paul

Reputation: 12799

How do I open a page's content from an Href link to display it inside a JQuery UI Dialog?

I have a link like this and I want to open its content and display it using the code below:

<a class="uimodal" href="/Administration/Contact">Contact</a> 

How can I make that link open the href content and display it inside of a jQuery UI modal dialog?

Upvotes: 4

Views: 21857

Answers (4)

Steven
Steven

Reputation: 19425

I'm loading content in a dialog box without using IFrame. This is how I do it:

First you have to initilize your dialog box. You can use something like this:

if (jQuery("#dialog_contact").length > 0) {
    jQuery("#dialog_contact").dialog({
        title: "File browser",
        modal: true,
        autoOpen: false,
        height: 700,
        width: 800,
        closeText: 'hide',
        open: function () {
            // Here I load the content. This is the content of your link.
            jQuery("#dialog_contact").load("../wp-content/plugins/my_plugin/somPage.php", function () {});
        }
    });
}

// Then open the dialog window on click
jQuery('.uimodal').live('click', function () {
    jQuery('.dialog_contact').dialog('open')
});

See more info here: http://jqueryui.com/demos/dialog/

Upvotes: 5

hamid reza mansouri
hamid reza mansouri

Reputation: 11333

In this code dialog size and title is declare in link

<script type="text/javascript">

    function tb_parseQuery(query) {
        var Params = {};
        if (!query) { return Params; }// return empty object
        var Pairs = query.split(/[;&]/);
        for (var i = 0; i < Pairs.length; i++) {
            var KeyVal = Pairs[i].split('=');
            if (!KeyVal || KeyVal.length != 2) { continue; }
            var key = unescape(KeyVal[0]);
            var val = unescape(KeyVal[1]);
            val = val.replace(/\+/g, ' ');
            Params[key] = val;
        }
        return Params;
    }
    $(document).ready(function () {
        $('a.uimodal').bind('click', function () {

        var $this = $(this);
        var url = $this.attr("href");



        var queryString = url.replace(/^[^\?]+\??/, '');
        var params = tb_parseQuery(queryString);
        TB_WIDTH = (params['width'] * 1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
        TB_HEIGHT = (params['height'] * 1) + 40 || $(document).height(); //defaults to 440 if no paramaters were added to URL
            TB_Title = (params['title']);



        $('<div>').dialog({
            modal: true,
            open: function () {
                $(this).load(url);
            },
            height: TB_HEIGHT,
            width: TB_WIDTH,
            title: TB_Title
        });
        return false;
    });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a class="uimodal" href="Dialog.aspx?height=350&width=700&title=تست"> click</a>
    </div>
    </form>
</body>
</html>

Upvotes: 0

bmancini
bmancini

Reputation: 2028

The best way is to use an Ajax Load operation to retrieve the content into a new element. Then when the data is loaded, call the modal on that element:

$('a.uimodal').bind('click', function() {
   var $this = $(this);
   var outputHolder = $("<div id='.uimodal-output'></div>");
   $("body").append(outputHolder);
   outputHolder.load($this.attr("href"), null, function() {
      outputHolder.dialog(// whatever params you want);
   });
   return false;
});

AJAX Load: http://api.jquery.com/load/ Dialog Options: http://jqueryui.com/demos/dialog/

Note: You could also display the modal while the AJAX page is loading by putting outputHolder.dialog(//...) prior to calling the load method.

Upvotes: 7

Kissaki
Kissaki

Reputation: 9227

You’ll have to create an iframe and open that in your dialog.

Thus, something like

jQuery('<iframe/>').attr('src', jQuery('.uimodal').attr('href')).dialog('open');

In more detail: The jQuery UI dialog() can only display DOM-elements, you’ll have to first add something to your DOM which displays the URL.

http://jqueryui.com/demos/dialog/

Upvotes: 1

Related Questions