views:

7797

answers:

3

I have a page, i want it to disploay display it content in a modal dialog (jquery UI dialog) as soon as the page is loaded.

  $(document).ready(function(){
    $("#example").dialog();
  });

<div id="example" class="flora" title="This is my title">
    I'm in a dialog!
</div>

Thanks

A: 

So what's wrong with the code you provided? Is it not working or...?

As far as I can see, that would work perfectly. I would suggest you use $(function() { instead of $(document).ready(function(){. It's shorter and easier to read. :P

Salty
Shorter doesn't equal easier to read. I think $(document).ready() is perfectly comprehensible and very descriptive.
tvanfosson
I agree with @tvanfosson in any of my presentation I use $(document).ready(func) because i think its actually easier to read that way.
bendewey
+3  A: 

Your div tag isn't properly formatted and it needs to be closed. The following worked for me, but it needs proper CSS files.

<html>
<head>
<script type="text/javascript" language="javascript"
        src="jquery/jquery.js"></script>
<script type="text/javascript" language="javascript"
        src="jquery/jquery.ui.js"></script>
<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        $("#example").dialog();
    });
</script>
</head>
<body>
    <div id="example" class="flora" title="This is my title">
        I'm in a dialog!
    </div>
</body>
</html>
tvanfosson
A: 

Wayne Khan is right in that

the default behavior is to open when you call dialog(), unless you set autoOpen to false.

and tvanfosson has it nearly correct, though the default dialog is not Modal. To display a modal window, you must set the modal option to true

To illustrate, here's a trimmed-down excerpt from a small project I was working on tonight:

...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="./jquery-ui-personalized-1.6rc6.min.js"></script>
<script type="text/javascript" src="./init.js"></script>
<link rel="stylesheet" href="./css.css" type="text/css" />
<script type="text/javascript">
    $(function() {
        $('#exampleNode').dialog({
            modal: 'true'
        });
    });
</script>
...


For your reference:

drfloob