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

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

java - Getting exception in JDBC thin driver -