PiaklA
PiaklA

Reputation: 505

How to avoid creating the duplicate dialog boxes in jquery

In my Footer Page

   Link 1 , Link 2  , Link 3 

Any of these links clicked will open a dialog box with data content and footer file. So ,Dialog will look like:

       Data 
       Link 1 , Link 2 , Link 3

And when I click on one of the link from Dialog it opens another dialog ,So this logic is going in to a infinite loop.

Is there a way to avoid the duplication of this dialog boxes ?

Open Function:

$(function() {

    $('#dialog').dialog('close');   
    // Trying it here but not sure if this is the right place  to do 
   // I want to close all dialog boxes before opening one 

    $( "#dialog" ).dialog({
        modal:true,
        height:600,
        width:600,
        my: "center",
        at: "center",
        of:window,
        resizable:false,
        closeOnEscape:false,
        open:function (event, ui) {
                 $('#dialog').load('/contact.jsp');
        }
    });

    $( "#dialog" ).dialog("option", "title", url);
});

Still thinking about if I am placing .close in the right place to begin with ?

Upvotes: 0

Views: 1339

Answers (3)

sdespont
sdespont

Reputation: 14025

Add a GET parameter to the pages called through your links like mypage.php?dialog=true

and in your footer, check if this parameter is present before displaying the links :

<?php if(!isset($_REQUEST['dialog'])) : ?>
HTML code to display your link <a href="mypage.php?dialog=true">link</a>
<?php endif; ?>

Upvotes: 0

jos
jos

Reputation: 431

Assuming you have a function that's creating this stuff dynamically, thus the loop. If so, a solution to avoid duplication is give the Dialog box a class name unique to itself and prior to any creation, use a jquery call to delete any element with that class name.

Here's more info on .remove()

Upvotes: 1

Jonathan Wilson
Jonathan Wilson

Reputation: 4305

Don't include the footer file when loading a dialog.

Upvotes: 0

Related Questions