Prateek
Prateek

Reputation: 274

Modal Dialog Box using JQuery & AJAX

I've been trying to add a modal dialog box in my page, which is displayed on the click over a hyperlink, and fetches content from another URL. Problem is, I couldn't find a way to make it modal, as it is still possible to interact with the background page, and I don't want that.

Here's the code I am using,

HTML

<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="login.html">Open as dialog</a>
  </body>

</html>

CSS

.loading {
  background: url(/img/spinner.gif) center no-repeat;
}

jQuery

$(function() {
  var ajaxDialog = $('<div id="ajax-dialog" style="display:hidden"></div>').appendTo('body');
  ajaxDialog.dialog({
    autoOpen: false
  });
  $('a.ajax').live('click', function() {
    ajaxDialog.load(this.href);
    ajaxDialog.dialog("open");
    return false;
  });
});

Please, if anyone can help to make it modal. Thanks in advance.

Upvotes: 1

Views: 6887

Answers (1)

tedwards947
tedwards947

Reputation: 380

Have you tried using ajaxDialog.dialog("modal","true"); ?

http://api.jqueryui.com/dialog/#option-modal

Upvotes: 1

Related Questions