diff --git a/src/featherlight.js b/src/featherlight.js
index 669bfef9..5a0c46f8 100644
--- a/src/featherlight.js
+++ b/src/featherlight.js
@@ -534,6 +534,20 @@
}
},
+ beforeOpen: function(_super, event) {
+ this._previouslyActive = document.activeElement;
+ document.activeElement.blur();
+ return _super(event);
+ },
+
+ afterClose: function(_super, event) {
+ if (this._previouslyActive) { // Bulletproofing
+ this._previouslyActive.focus();
+ this._previouslyActive = null;
+ }
+ return _super(event);
+ },
+
onResize: function(_super, event){
this.resize(this.$content.naturalWidth, this.$content.naturalHeight);
return _super(event);
diff --git a/test/featherlight.html b/test/featherlight.html
index cf191f8e..06f88368 100644
--- a/test/featherlight.html
+++ b/test/featherlight.html
@@ -60,6 +60,8 @@
Hello
world
+
+