jQuery dialog from external content

How to load external content into a jQuery Dialog.

First the style

<style type="text/css">
    #terms-and-conditions-content{display:none}
</style>

Then the JavaScript

<script type="text/javascript">
    // <![CDATA[
        $(document).ready(function(){ $('#terms-and-conditions').click(function(e){ e.preventDefault();
        var url = $(this).attr('href');
        $('#terms-and-conditions-content').load(url);
        $("#terms-and-conditions-content").dialog({ width:800,modal: true,buttons: { "Close": function() { $(this).dialog("close"); } } }); }); });
    // ]]>
</script>

Then the HTML

    <a id="terms-and-conditions" href="/terms.html">Click Here</a>

Should be straight forward. Just point the link to the file you want to pull into the Dialog box.

Don’t forget that the Dialog is a part of jQuery UI, not just the standard jQuery – you will need to include both.

<script type="text/javascript" src="http<?=$_SERVER['HTTPS']=='on'?'s':''?>://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
    // <![CDATA[
        !window.jQuery && document.write('<script src="/js/jquery-1.6.2.min.js"></script>')
    // ]]>
</script>
<script type="text/javascript" src="/js/jquery-ui-1.8.16.custom.min.js"></script>

Share
You can leave a response, or trackback from your own site.

8 Responses to “jQuery dialog from external content”

  1. decolink says:

    This is the best post on this topic i have ever read.I am really very impressed with the blogging

  2. John says:

    Hello there, just became aware of your blog through Google, and found that it’s really informative. I’m gonna watch out for brussels. I’ll appreciate if you continue this in future. A lot of people will be benefited from your writing. Cheers!

  3. Christy says:

    Thanks for this great blog!

  4. Dockstader says:

    I discovered exactly what I was taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  5. Anonymous says:

    [...]jQuery dialog from external content | Mike Johnson’s Personal Blog[...]…

  6. Burt says:

    Do you mind if I quote a few of your posts as long as I provide credit and sources back to your website? My blog is in the very same area of interest as yours and my users would genuinely benefit from some of the information you present here.

  7. AfterDarkMike says:

    Go to town :)

  8. Yung says:

    Awsome blog! I

Leave a Reply

Comments links could be nofollow free.

Twitter Delicious Facebook Digg Stumbleupon Favorites More