diff --git a/horizontal-tabs/horizontal-tabs.js b/horizontal-tabs/horizontal-tabs.js
index 977e1b6..6429e8f 100644
--- a/horizontal-tabs/horizontal-tabs.js
+++ b/horizontal-tabs/horizontal-tabs.js
@@ -65,6 +65,21 @@ Drupal.behaviors.horizontalTabs = {
   }
 };
 
+window.addEventListener("hashchange", function () {
+  var tab_focus;
+  // If the current URL has a fragment and one of the tabs contains an
+  // element that matches the URL fragment, activate that tab.
+  if (window.location.hash && window.location.hash !== '#') {
+    tab_focus = $(window.location.hash).closest('.horizontal-tabs-pane');
+  }
+  else {
+    tab_focus = $('.horizontal-tabs-pane:first');
+  }
+  if (tab_focus.length) {
+    tab_focus.data('horizontalTab').focus();
+  }
+}, false);
+
 /**
  * The horizontal tab object represents a single tab within a tab group.
  *
@@ -79,6 +94,7 @@ Drupal.horizontalTab = function (settings) {
 
   this.link.click(function () {
     self.focus();
+    self.updateUrlHash();
     return false;
   });
 
@@ -87,6 +103,7 @@ Drupal.horizontalTab = function (settings) {
   this.link.keydown(function(event) {
     if (event.keyCode == 13) {
       self.focus();
+      self.updateUrlHash();
       // Set focus on the first input field of the visible fieldset/tab pane.
       $("fieldset.horizontal-tabs-pane :input:visible:enabled:first").focus();
       return false;
@@ -122,6 +139,21 @@ Drupal.horizontalTab.prototype = {
     // Mark the active tab for screen readers.
     $('#active-horizontal-tab').remove();
     this.link.append('<span id="active-horizontal-tab" class="element-invisible">' + Drupal.t('(active tab)') + '</span>');
+
+  },
+
+  /**
+   * Change page hash, but avoid page jump to targeted content.
+   */
+  updateUrlHash: function () {
+    var targetHash = this.link.attr('href');
+    if (document.location.hash != targetHash) {
+      var targetId = targetHash.replace(/^#/, '');
+      var targetElem = $(targetHash);
+      targetElem.attr('id', targetId + '-horizontal-tab-no-jump');
+      document.location.hash = targetId;
+      targetElem.attr('id', targetId);
+    }
   },
 
   /**
