dialog - Get instance of JQuery UI popup -
i creating jquery ui popup way:
function showjquerystandarddialog(searchtarget, title, width, height, closefunction) { var $dialog = $('<div id="dialogdiv"><iframe id="dialogiframe" frameborder="no" scrolling="auto" src="' + searchtarget + '" width="' + (width - 50) + 'px" height="' + (height - 50) + 'px"></iframe></div>'); $dialog.dialog( { modal: true, title: title, show: 'slide', width: width, height: height, closeonescape: true, close: function (event, ui) { if (typeof closefunction === 'function') closefunction(); } }); }
i want instance of popup elsewhere in code can close it. tried:
var $dialog = $('#dialogdiv'); var $dialog = $('.ui-dialog'); var $dialog = $('.ui-dialog-content');
but returns empty object. note if put above code in close
method of dialog, works fine. shall conclude can't access popup outside init code?
found way:
function showjquerystandarddialog(searchtarget, title, width, height, closefunction) { $dialog = $('<div id="dialogdiv"><iframe id="dialogiframe" frameborder="no" scrolling="auto" src="' + searchtarget + '" width="' + (width - 50) + 'px" height="' + (height - 50) + 'px"></iframe></div>'); $dialog.dialog( { modal: true, title: title, show: 'slide', width: width, height: height, closeonescape: true, close: function (event, ui) { if (typeof closefunction === 'function') closefunction(); } }); /* important bit */ $(document).bind('close-dialog', function () { $dialog.dialog('close'); }); }
then call parent.$(parent.document).trigger('close-dialog');
when want close dialog.
Comments
Post a Comment