views:

16004

answers:

2

The ajax tabs work perfectly well. It's pretty straightforward with that part. However, getting the ajax UI Dialog modal window to trigger off of a link has been un-succesful.

Any help in this would be appreciated.

+1  A: 
<a href="javascript:void(0)" onclick="$('#myDialog').dialog();">
  Open as dialog
</a>

<div id="myDialog">
I have a dialog!
</div>

See the example I posted on jsbin.com.

altCognito
Actually, I'm not sure this is what you're looking for, I'll come back and update unless someone else picked it up. Can you clarify what is causing the issue?
altCognito
+24  A: 

Nothing easier than that man. Try this one:

<?xml version="1.0" encoding="iso-8859-1"?>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"&gt;&lt;/script&gt;
</head>
<body>
    <a class="ajax" href="http://www.google.com"&gt;
      Open as dialog
    </a>

    <script type="text/javascript">
    $(function (){
        $('a.ajax').click(function() {
            var url = this.href;
            var dialog = $('<div style="display:hidden"></div>').appendTo('body');
            // load remote content
            dialog.load(
                url, 
                {},
                function (responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog();
                }
            );
            //prevent the browser to follow the link
            return false;
        });
    });
    </script>
</body>
</html>

Note that you can't load remote from local, so you'll have to upload this to a server or whatever. Also note that you can't load from foreign domains, so you should replace href of the link to a document hosted on the same domain (and here's the workaround).

Cheers

jek
Thanks, this helped me!
Preston Marshall
this example doesn't work for me.. uploaded to my server.
FFish
@FFish updated answer with a note about cross domain ajax. You cannot just copy'n'paste the source unless you can upload files to http://www.google.com/ ;)
jek
Ok, cheers. Got it working on localhost (XAMPP) loading a file with a relative path.
FFish