javascript - Angular close modal dialog when pressing escape in Chrome and Safari -


i have following directive attached element closes sharepoint 2013 modal dialog when user presses esc key.

    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();             };         }     }; }); 

it works in ie , firefox, not in chrome or safari. suggestions?

i forgot update answer. $document answer.

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);             });         }     }; }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -