From 2e1ce294d6387dd28ebe7af1219d393b4586dc45 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Fri, 29 Aug 2014 18:24:17 +0200 Subject: [PATCH] Consistent fragment target behavior. --- heroik.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/heroik.js b/heroik.js index bca710e..88b1d32 100644 --- a/heroik.js +++ b/heroik.js @@ -30,11 +30,7 @@ function scrollToId (id) { function open (event) { var href = this.href; var target = this.target === "_parent" ? window.parent : window; - - if (this.getAttribute('href')[0] === "#") - scrollToId(this.getAttribute('href').slice(1)); - else - target.location.href = this.href; + target.location.href = this.href; event.preventDefault(); } @@ -44,6 +40,10 @@ window.addEventListener('load', function () { scrollToId(location.hash.slice(1)); }); +window.addEventListener('hashchange', function () { + scrollToId(location.hash.slice(1)); +}); + window.addEventListener('DOMContentLoaded', function () { if (navigator.standalone) document.body.className += ' standalone'; -- 2.30.2