jquery-ui-dialog-대화 상자 닫기 이벤트에 연결하는 방법
jquery-ui-dialog
플러그인을 사용하고 있습니다
일부 상황에서 대화 상자가 닫힐 때 페이지를 새로 고치는 방법을 찾고 있습니다.
대화 상자에서 닫기 이벤트를 캡처하는 방법이 있습니까?
닫기 버튼을 클릭하면 코드를 실행할 수 있지만 오른쪽 상단의 x 또는 x로 닫는 사용자를 다루지 않습니다.
찾았습니다!
다음 코드를 사용하여 close 이벤트를 잡을 수 있습니다.
$('div#popup_content').on('dialogclose', function(event) {
alert('closed');
});
분명히 나는 내가해야 할 일로 경고를 바꿀 수 있습니다.
편집 : Jquery 1.7부터 bind ()가 on ()되었습니다.
대화 상자를 만들면서도 할 수 있다고 생각합니다 (내가 한 프로젝트에서 복사).
dialog = $('#dialog').dialog({
modal: true,
autoOpen: false,
width: 700,
height: 500,
minWidth: 700,
minHeight: 500,
position: ["center", 200],
close: CloseFunction,
overlay: {
opacity: 0.5,
background: "black"
}
});
노트 close: CloseFunction
$("#dialog").dialog({
autoOpen: false,
resizable: false,
width: 400,
height: 140,
modal: true,
buttons: {
"SUBMIT": function() {
$("form").submit();
},
"CANCEL": function() {
$(this).dialog("close");
}
},
**close: function() {
alert('close');
}**
});
$( "#dialogueForm" ).dialog({
autoOpen: false,
height: "auto",
width: "auto",
modal: true,
my: "center",
at: "center",
of: window,
close : function(){
// functionality goes here
}
});
dialog의 "close"속성은 close 이벤트를 제공합니다.
U는 이것을 시도 할 수도 있습니다
$("#dialog").dialog({
autoOpen: false,
resizable: true,
height: 400,
width: 150,
position: 'center',
title: 'Term Sheet',
beforeClose: function(event, ui) {
console.log('Event Fire');
},
modal: true,
buttons: {
"Submit": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
이것이 나를 위해 일한 것입니다 ...
$('#dialog').live("dialogclose", function(){
//code to run on dialog close
});
As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document.
Because no one actually created an answer with using .on()
instead of bind()
i decided to create one.
$('div#dialog').on('dialogclose', function(event) {
//custom logic fired after dialog is closed.
});
add option 'close' like under sample and do what you want inline function
close: function(e){
//do something
}
If I'm understanding the type of window you're talking about, wouldn't $(window).unload() (for the dialog window) give you the hook you need?
(And if I misunderstood, and you're talking about a dialog box made via CSS rather than a pop-up browser window, then all the ways of closing that window are elements you could register click handers for.)
Edit: Ah, I see now you're talking about jquery-ui dialogs, which are made via CSS. You can hook the X which closes the window by registering a click handler for the element with the class ui-dialog-titlebar-close.
More useful, perhaps, is you tell you how to figure that out quickly. While displaying the dialog, just pop open FireBug and Inspect the elements that can close the window. You'll instantly see how they are defined and that gives you what you need to register the click handlers.
So to directly answer your question, I believe the answer is really "no" -- there's isn't a close event you can hook, but "yes" -- you can hook all the ways to close the dialog box fairly easily and get what you want.
You may try the following code for capturing the closing event for any item : page, dialog etc.
$("#dialog").live('pagehide', function(event, ui) {
$(this).hide();
});
참고URL : https://stackoverflow.com/questions/171928/jquery-ui-dialog-how-to-hook-into-dialog-close-event
'Programming' 카테고리의 다른 글
iOS 7 이상에서 Base64 디코딩 (0) | 2020.05.17 |
---|---|
고정 너비로 HTML 버튼의 텍스트를 줄 바꿈하는 방법은 무엇입니까? (0) | 2020.05.17 |
OS X“El Capitan”에 gem을 설치할 수 없습니다 (0) | 2020.05.17 |
MySQL의 현재 시간대를 어떻게 얻습니까? (0) | 2020.05.17 |
CSS에서 PNG 이미지의 그림자 (0) | 2020.05.17 |