当用户按下esc
键时,我将以下指令附加到关闭SharePoint 2013模式对话框的元素。
app.directive("closeDialog", function() {
return {
link: function(scope, element, attrs) {
document.onkeypress = function(e) {
var dialog = SP.UI.ModalDialog.get_childDialog();
if(dialog || dialog != null) {
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, null);
}
scope.$apply();
};
}
};
});
适用于IE和Firefox,但不适用于Chrome或Safari。有什么建议吗?
答案 0 :(得分:3)
我忘了更新答案。 $document
就是答案。
app.directive("closeDialog", function($document) {
function closeModalDialog(scope) {
var dialog = SP.UI.ModalDialog.get_childDialog();
if(dialog != null) {
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, null);
}
scope.$apply();
}
return {
link: function(scope, element, attrs) {
$document.on("keydown", function(e) {
closeModalDialog(scope);
});
}
};
});