0
$(top.document).ready(function () {   

   $(document).click(processAction);



function processAction(e){
    var clicked = e.target;
newDialog("You've Clicked On A Link !")

function newDialog(mytitle){
   var $dialog = $('<div id="myunique"></div>')
        .html("<a href='http://sss.com'>click</a>")
        .dialog({
            autoOpen: false,
            modal: true,
            title: mytitle
        });
    $dialog.dialog('open');
    return false
}

});

The problem I am having is that when I click anywhere in the dialog, a new dialog popups, and it seems to produce several of these in a row.

My goal is: catch all the clicks on page EXCEPT the elements inside the dialog.

KJW
  • 15,035
  • 47
  • 137
  • 243

1 Answers1

1

your problem is probably here:

$(document).click(processAction);

this means that any time you click anywhere on your page, the processAction() method runs!

change this so that it only runs when a button or link is clicked and it should solve your problem.

EDIT: according to your edit you want to capture clicks outside your dialog box. Check out this thread for instructions on how to do this.

Community
  • 1
  • 1
Jason
  • 51,583
  • 38
  • 133
  • 185
  • i tried $('body').delegate('*:not(#mymenu *)','click', processAction); and it doesn't work – KJW Sep 23 '10 at 23:34
  • yes, because that means that whenever someone clicks anywhere on the page it will run your method. set your click handler to something like `$('.mylink').click(processAction)` – Jason Sep 23 '10 at 23:36
  • even doing this $('body').delegate('a:not(#mymenu *)','click', processAction); results in a new dialog spawning when I click the link inside the dialog.... – KJW Sep 23 '10 at 23:38
  • the reason I am doing this is, I need to catch all the clicks EXCEPT the elements inside the dialog. – KJW Sep 23 '10 at 23:39
  • tried the event.stopPropagation method but as soon as I click on teh link, the dialog appears and then it navigates to the following page. – KJW Sep 24 '10 at 01:22