Sie sind auf Seite 1von 3

http://10.110.0.101/sgs103/rr.

php

Open as dialog Stack Exchange log in | careers | chat | meta | about | faq

Stack Overflow Questions Tags Users Badges Unanswered Ask Question

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. up vote 15 down vote favorite 12 Any help in this would be appreciated. jquery jquery-ui jquery-ajax modal-dialog asked Apr 30 '09 at 20:56 link|edit|flag

4 Answers
active oldest votes 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"></script> <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"></script> </head> <body> <a class="ajax" href="http://www.google.com"> 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 up dialog.load( vote url, 43 {}, function (responseText, textStatus, XMLHttpRequest) { down dialog.dialog(); vote } ); //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 answered Sep 25 '09 at 12:13 link|edit|flag edited Oct 1 '10 at 12:39 jek 49636 Thanks, this helped me! Preston Marshall Aug 16 '10 at 1:40 this example doesn't work for me.. uploaded to my server. FFish Sep 30 '10 at 16:20

1 de 3

16-05-2011 10:52

http://10.110.0.101/sgs103/rr.php

@FFish updated answer with a note about cross domain ajax. You cannot just copy'n'paste the source unless you can upload files to google.com ;) jek Oct 1 '10 at 12:41 Ok, cheers. Got it working on localhost (XAMPP) loading a file with a relative path. FFish Oct 2 '10 at 10:35 jquery.load does not seem to ejecute the javascript contained in the remote content Guido Jan 9 at 20:53 show 3 more comments To avoid adding extra divs when clicking on the link multiple times, and avoid problems when using the script to display forms, you could try a variation of @jek's code.
$('a.ajax').live('click', function() { var url = this.href; var dialog = $("#dialog"); if ($("#dialog").length == 0) { dialog = $('<div id="dialog" 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; });`

up vote 4 down vote

answered Feb 11 at 21:30 link|edit|flag CGK 76910 Good point indeed.. would you mind if I include this tweak in my original answer? jek Feb 18 at 9:08 @jek no problem! CGK Feb 18 at 15:56
<a href="javascript:void(0)" onclick="$('#myDialog').dialog();"> Open as dialog </a> <div id="myDialog"> I have a dialog! </div>

up vote 1 down vote

See the example I posted on jsbin.com. answered Apr 30 '09 at 20:59 link|edit|flag altCognito 12.9k2246 1 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 Apr 30 '09 at 21:04 //Properly Formatted
<script type="text/Javascript"> $(function () { $('<div>').dialog({ modal: true, open: function () { $(this).load('mypage.html'); }, height: 400, width: 600, title: 'Ajax Page' }); });

up vote 1 down vote

edited Mar 21 at 14:15 answered Feb 10 at 18:47 link|edit|flag Dorababu 2,1101315 nicktea 111

2 de 3

16-05-2011 10:52

http://10.110.0.101/sgs103/rr.php

3 de 3

16-05-2011 10:52

Das könnte Ihnen auch gefallen