Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  191] [ 3]  / answers: 1 / hits: 34730  / 13 Years ago, mon, october 31, 2011, 12:00:00

I'm trying to have my dialog auto-close three seconds after opening. I've tried the following methods:



setTimeout($(#mydialog).dialog('close'), 3000);


Here it is in context:



$(#acknowledged-dialog).dialog({
height: 140,
modal: true
});

setTimeout($(#acknowledged-dialog).dialog('close'), 3000);


But with this method, it doesn't even show! I'm guessing the the close method is getting called immediately after it gets shown on the page. The log shows no errors.



I've also tried binding to the dialogopen event:



$(#acknowledged-dialog).bind('dialogopen', function(event, ui) {
setTimeout($(this).dialog('close'), 3000);
});
$(#acknowledged-dialog).dialog({
height: 140,
modal: true
});


The dialog shows, but does not auto-close. No error in the logs here either.



Am I not able to use 'this' in the argument for $ in setTimeout?


More From » jquery

 Answers
7

setTimeout is calling on the the return value of $(#mydialog).dialog(close) after 3 seconds. you want to throw the whole thing as a string, and it should work just fine. Also, I don't think you want to bind 'dialogopen' before you initialize the dialog. Below should work just fine:



$(#acknowledged-dialog).dialog({
height: 140,
modal: true,
open: function(event, ui){
setTimeout($('#acknowledged-dialog').dialog('close'),3000);
}
});

[#89362] Friday, October 28, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
miles

Total Points: 256
Total Questions: 111
Total Answers: 104

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;